Home > DeveloperSection > Forums > Javascript bottun click is not work in asp.net
ezra heywood
ezra heywood

Total Post:145

Posted on    November-20-2014 10:10 PM

 ASP.Net JavaScript  Client Side Scripting 

 1 Reply(s)
 836  View(s)
Rate this:

I am trying to call from JS to C# function. I can not use ajax. I have tried to create a ASP.NET button when it clicked it calls the C# function and call the click function from JS:


<asp:Button runat="server" ID="UploadButton" OnClick="Upload_Click" />


alert("Before CLICK");


alert("After CLICK");


protected void Upload_Click(object sender, EventArgs e)




The problem is that the click event from JS does not working. I have tried to write after the first line of the JS code an alert to see if the code rich to that line but I can only see "After CLICK".

Kamlakar Singh
Kamlakar Singh

Total Post:28

Posted on    November-21-2014 12:16 AM

You should set the ClientIDMode to Static

<asp:Button runat="server" ID="UploadButton" ClientIDMode="Static" OnClick="Upload_Click" />

Otherwise, it will have some randomized id, generated by ASP.NET, setting the CLientIDMode to Static, you're saying ASP.NET not to meddle with your ids and keep them intact.

Other option would be to use the ClientID property which will have the value of the automatically generated id like

document.getElementById('<%= UploadButton.ClientID %>').click();

Don't want to miss updates? Please click the below button!

Follow MindStick