Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  57] [ 2]  / answers: 1 / hits: 37823  / 11 Years ago, fri, august 23, 2013, 12:00:00

I am using a aspx page which is having a button.



 <asp:Button ID=savebtn runat=server OnClick=savebtn_Click Style=display: none />


There are two ways to cause post back as shown in the below code.



 $(document).ready(function () {
var id = document.getElementById('<%= savebtn.ClientID %>');
//Cause post back & calls page load but not savebtn_Click event
__doPostBack('<%= savebtn.ClientID %>', 'OnClick');

});

$(document).ready(function () {
var id = document.getElementById('<%= savebtn.ClientID %>');
//Cuase postback & calls both PageLoad and savebtn_Click events.
//If I use method, There is no way to know which control caused postback
id.click();

});


When I use __doPostBack, It calls page load event but not btn click event.



Is there any way using __doPostBack to trigger Page Load as well as savebtn_Click event.



If I use id.click(); as shown above, I am able to call savebtn_Click but it does not tells me which control caused the post back.


More From » c#

 Answers
69

have you tried using the UniqueID instead of the ClientID?



__doPostBack('<%= savebtn.UniqueID %>', );


Also have a look at this quick tutorial on dopostback:


[#76195] Thursday, August 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
siena

Total Points: 199
Total Questions: 91
Total Answers: 91

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;