levent_kalay
levent_kalay

Reputation: 11

how can i call a function in a onclick method of image button in asp.net

I have to call a function to send some data in onclick method

   <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>

Upvotes: 0

Views: 4786

Answers (2)

levent_kalay
levent_kalay

Reputation: 11

asp.net side

<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# side 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";
    }

also i tried to call javascript function like

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

</script> 

Upvotes: 0

Mike Christensen
Mike Christensen

Reputation: 91608

Use OnClientClick, like so:

<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; "
/>

Upvotes: 3

Related Questions