Skip to main content

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>




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

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?