aspx页面中有一段JavaScript函数
<script type="text/javascript">
function showID()
{
   var id= this.id;
   alert(id);
}
</script><body>
    <form id="form1" runat="server">
    <div>
        <asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/ad.xml" KeywordFilter="1"   
        Target="_blank"  />
    </div>
    </form>
</body>现在我想在后台位控件添加一个单击事件:
.cs 中添加如下代码:
 protected void Page_Load(object sender, EventArgs e)
    {
        AdRotator1.Attributes.Add("onclick", "showID()");// 希望在点击时调用前台的showID()函数
    }
但是这样不能成功调用,在网上查了下说还要Page.ClientScript.RegisterStartupScript()注册,查了很久确实不知道改怎么办,只好求教给位了,麻烦大家吧具体代码写出来,我急用!谢谢了如果我的后台还有一个函数,又该怎么调用前台中JavaScript函数的id变量呢????

解决方案 »

  1.   

    Page.ClientScript.RegisterStartupScript(gettype,true,"<script>showID()</script>")你试试 你找找坛子有人发过这样的帖子 不过感觉你的那样应该没问题 你该一下你的js在调用一下<script type="text/javascript"> 
    function showID() 

      
      alert(11); 

    </script> 这样看看行不行
      

  2.   

                 this.Page.ClientScript.RegisterStartupScript(this.GetType(), "dd", "aa()", true); 
    这样调用前台的js 
    aa()是方法名
      

  3.   

    http://topic.csdn.net/t/20050301/11/3814756.htmlhttp://topic.csdn.net/t/20050330/15/3894659.html
      

  4.   

    function showID() 

      var id= this.id; 
      alert(id); 

    this.id哪来的? 要从后台得到?改成传参的形式
    function showID(id) 

      alert(id); 

    AdRotator1.Attributes.Add("onclick", "showID("+this.id+")");// 
      

  5.   

    function showID(obj) 

      var id= obj.id; 
      alert(id); 

    this.id哪来的? 要从后台得到?改成传参的形式 
    function showID(id) 

      alert(id); 

    AdRotator1.Attributes.Add("onclick", "showID(this)");// 
      

  6.   

    this.TextBox1.Attributes.Add("事件名","语句");