如何在asp.net中的onclick方法的图像按钮中调用函数

时间:2012-02-13 16:11:51

标签: javascript asp.net html

我必须调用一个函数来在onclick方法中发送一些数据

   <div class="yildiz"><asp:ImageButton ID=Imageid runat="server" Height="19px" 
                            ImageUrl="~/images/yildiz.png" onclick= "<%= someFunction('das') %>" Width="20px" 
                            style="position: relative; top: 13px; left:6px; float:left; "   /></div>

2 个答案:

答案 0 :(得分:3)

使用OnClientClick,如下所示:

<asp:ImageButton
   ID=Imageid runat="server"
   Height="19px"
   ImageUrl="~/images/yildiz.png"
   OnClientClick="someFunction('das')"
   Width="20px"
   style="position: relative; top: 13px; left:6px; float:left; "
/>

答案 1 :(得分:0)

asp.net方

<div class="yildiz"><asp:ImageButton ID=Imageid runat="server" Height="19px" 
   ImageUrl="~/images/yildiz.png" 
   OnClientClick="SomeMethod(<% j%>,  <% imageid%>)" Width="20px" 
   style="position: relative; top: 13px; left:6px; float:left; "   />

C#方面    public void SomeMethod(int numberOfStar,string imageId)         {

        this.baslik2.Text = "dsadsadsa";
        this.baslik.Text = "fasfsa";
        ImageButton4.ImageUrl = "images/yildiz-secili.png";
        ImageButton2.ImageUrl = "images/yildiz-secili.png";
    }

我也尝试调用像

这样的javascript函数
   <script type="text/javascript">
                        function SomeMethod(int j, string imageidd){
                            javascript: window.open("http://www.microsoft.com");
                             ImageButton2.ImageUrl = "images/yildiz-secili.png";
                        }    

</script>