I'm trying to create an asyncrhonous postback in ASP.NET using __doPostBack()
, but I have no idea how to do it. I want to use vanilla JavaScript.
Something simple like a button click can cause the __doPostBack()
event to fire. I'm just trying to learn how the mechanism works.
This is also a good way to get server-side controls to postback inside FancyBox and/or jQuery Dialog. For example, in FancyBox-div:
JavaScript:
Server-side Page_Load:
Here's a brief tutorial on how
__doPostBack()
works.To be honest, I don't use it much; at least directly. Many server controls, (e.g.,
Button
,LinkButton
,ImageButton
, parts of theGridView
, etc.) use__doPostBack
as their post back mechanism.Like others have said, you need to provide the UniqueID of the control to the __doPostback() method.
On the server, the submitted form values are identified by the name attribute of the fields in the page.
The reason why UniqueID works is because UniqueID and name are in fact the same thing when the server control is rendered in HTML.
Here's an article that describes what is the UniqueID:
This is how I do it
Old question, but I'd like to add something: when calling
doPostBack()
you can use the server handler method for the action.For an example:
Will fire, on server:
I didn't find a better way to get the argument, so I'm still using
Request["__EVENTARGUMENT"]
.I'd just like to add something to this post for
asp:button
. I've tried clientId and it doesn't seem to work for me:However, getting the UniqueId seems to post back to the server, like below:
This might help someone else in future, hence posting this.