Rajkumar Gs
asked on
Call Code-Behind Button Click Event or Function In JQuery
In ASPX Page, I have a dummy button
What I am trying to achieve is call this function in JQuery OR
Call the Dummybtn_Click, which will do this job
Do you know, how to achieve this ?
Hope this make sense to you.
Raj
<asp:Button id="Dummybtn" runat="server" style="display:none;" OnClick="Dummybtn_Click"/>
This is its code-behind click event code Protected Sub Dummybtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Dummybtn.Click
releaseTheDoc()
End Sub
I am using jquery external files
......
<script language="javascript" src="js/jquery.js"></script>
<script language="javascript" src="js/navigateaway.min.js"></script>
</head>
In navigateaway.min.js, file - a event will get trigger when user tries to navigate away from current page. I want to execute an sql update query on this event. Code behind VB function releaseTheDoc() will do this.What I am trying to achieve is call this function in JQuery OR
Call the Dummybtn_Click, which will do this job
Do you know, how to achieve this ?
Hope this make sense to you.
Raj
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
on your asp button change to this:
<asp:Button id="Dummybtn" UseSubmitBehavior ="false" runat="server" style="display:none;" OnClick="Dummybtn_Click"/>
then in the html generated you can see that the onclick on your input button will have a __doPostBack js function,
then just copy the onclick function that the input button generates and copy it and call it within your javascript function
<asp:Button id="Dummybtn" UseSubmitBehavior ="false" runat="server" style="display:none;" OnClick="Dummybtn_Click"/>
then in the html generated you can see that the onclick on your input button will have a __doPostBack js function,
then just copy the onclick function that the input button generates and copy it and call it within your javascript function
ASKER
Thanks Proculopsis for your input.
I know that -
But I tried this code-snippet, which NOT worked.
Your code is working - Thanks!
Good. Do you know - How can I call a code-behind function in JQuery ?
I know that -
But I tried this code-snippet, which NOT worked.
document.getElementbyid('Dummybtn').click();
Your code is working - Thanks!
document.getElementById( "Dummybtn" ).click();
Good. Do you know - How can I call a code-behind function in JQuery ?
ASKER
@eguilherme: I got the button click worked in JQuery. Though I tried your suggestion.
Button
Checked the HTML generated
PO-Details.txt
But I couldn't find that you suggested.
Button
<asp:Button id="Dummybtn" runat="server" UseSubmitBehavior="false" style="display:none;" />
Checked the HTML generated
PO-Details.txt
But I couldn't find that you suggested.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
RajkumarGSD:
in the html the button click of the dummybtn is:
javascript:WebForm_DoPostB ackWithOpt ions(new WebForm_PostBackOptions(&q uot;Dummyb tn", "", true, "", "", false, true))
so if you call
WebForm_DoPostBackWithOpti ons(new WebForm_PostBackOptions(&q uot;Dummyb tn", "", true, "", "", false, true))
in javascript you will simulate the button click
in the html the button click of the dummybtn is:
javascript:WebForm_DoPostB
so if you call
WebForm_DoPostBackWithOpti
in javascript you will simulate the button click
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Otherwise, when you do your jquery ajax call to a specific url in your site that is hitting an aspx page, the pageLoad for that page will be the method that runs. If you want to make it quick and dirty you can add code in your pageLoad method that will check the query string for a specific attribute and if it is present then you can call that specific method you are wanting to call on the server.
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["upda teID"] != null)
{
YourMethod(Request.QuerySt ring["upda teID"]);
}
}
In this case you would need to compose the url of your request to look something like this...
mypage.aspx?updateID=5
Of course updateID could be named whatever you wanted.
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["upda
{
YourMethod(Request.QuerySt
}
}
In this case you would need to compose the url of your request to look something like this...
mypage.aspx?updateID=5
Of course updateID could be named whatever you wanted.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Guys for your suggestions.
I'll go through your comments and will be back soon
Raj
I'll go through your comments and will be back soon
Raj
ASKER
@eguilherme:
When I tried this code
When I tried this code
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Dummybtn", "", true, "", "", false, true))
instead of$('#Dummybtn').trigger('click');
not triggering button click
ASKER
Guys. I really appreciate your inputs.
Since I am in a tight timeline, I am going with button click which is working for me.
Once I have time, I will try your alternative suggestions. I know that is the better solution.
Since I am in a tight timeline, I am going with button click which is working for me.
Once I have time, I will try your alternative suggestions. I know that is the better solution.
ASKER
This is regarding calling a C# function in Javascript
C# Code
But this is not working with external file which is having jquery codes.
C# Code
public string strName = string.Empty;
public void TestFunction()
{
strName = "Raj";
}
Javascript Function <script type="text/javascript" language="javascript">
function init()
{
alert('hello ');
<%TestFunction();%>;
alert('<%=strName%>');
}
</script>
But this is not working with external file which is having jquery codes.
ASKER
Thanks to you all
Raj
Raj
hi..
i have a aspx page it contains a usercontrol...when i click button in the user control a popup opens using jquery dialog ...popup is in the div tag in usercontrol....popup contains a button.......
When i click button in popup no code behind action taking place....?
i have a aspx page it contains a usercontrol...when i click button in the user control a popup opens using jquery dialog ...popup is in the div tag in usercontrol....popup contains a button.......
When i click button in popup no code behind action taking place....?
ASKER