Friday, February 17, 2012

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>

2 comments:

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

    ReplyDelete
  2. 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>

    ReplyDelete