Click () Event in javascript with PARAM?

I use the click () event to call a method in Code Behind, for example:

HTML

<asp:button bordercolor="White" id="btnAddGS" onclick="AddGSBandeira" runat="server"> 

JAVASCRIPT

 $("#ctl00_ContentPlaceHolder1_btnAddGS").click(); 

WITH#

 public void AddGSBandeira(object sender, EventArgs e) { } 

Its working normally, but I need to pass a parameter in a javascript call, for example:

.

$ ("# ctl00_ContentPlaceHolder1_btnAddGS") click ("PARAM");

But I don't know how this works ... can anyone help?

+4
source share
2 answers

It is best to create a hidden control and populate it with value using JavasScript on the click event. Your code behind will be able to access this value in your postback (AJAX or otherwise).

Markup

 <asp:HiddenField ID="myHiddenField" runat="server" /> <asp:button bordercolor="White" id="btnAddGS" onclick="AddGSBandeira" onclientclick="SetHiddenValue()" runat="server"> 

Javascript

 function SetHiddenValue() { document.getElementById("<%=myHiddenField.ClientID%>").value = "[Your value here]"; } 

WITH#

 public void AddGSBandeira(object sender, EventArgs e){} { var jsVal = myHiddenField.Value; } 
+1
source

You can do this with trigger .

http://api.jquery.com/trigger/

 $("#ctl00_ContentPlaceHolder1_btnAddGS").trigger("click",["param"]); 

I believe that the second parameter to run should be an array of arguments to jump to the function.

0
source

All Articles