Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to use __doPostBack()?

Is it OK to use __doPostBack() or it is not recommended because it is generated from ASP.Net and we are not sure if they changed it in a next version of ASP.Net.

like image 461
Homam Avatar asked Mar 27 '11 11:03

Homam


People also ask

What is the use of __ doPostBack in JavaScript?

Doing or Raising Postback using __doPostBack() function from Javascript in Asp.Net. Postback is a mechanism where the page contents are posted to the server due to an occurrence of an event in a page control. For example, a server button click or a Selected Index changed event when AutoPostBack value is set to true.

What does postback mean?

In web development, a postback is an HTTP POST to the same page that the form is on. In other words, the contents of the form are POSTed back to the same URL as the form. Postbacks are commonly seen in edit forms, where the user introduces information in a form and hits "save" or "submit", causing a postback.

What is __ Eventargument?

The __EVENTARGUMENT is any relevant event arguments regarding the control performing the postback. For most controls, there are no specialized event arguments, and since event arguments are different for every control, null is passed to represent a default argument should be created during the event sequence.


1 Answers

I would advice against it, since it's internal stuff of ASP.NET and was never meant to be used directly.

Instead, what I'm doing when I need to "manually" trigger PostBack is adding hidden "server side" button with the proper OnClick:

<asp:Button id="btnDummy" runat="server" OnClick="Foo" style="display: none;" />

Then the JS is:

document.getElementById("<%=btnDummy.ClientID%>").click();

This way I don't care how post back happens, I just trigger the natural flow of events.

like image 72
Shadow Wizard Hates Omicron Avatar answered Oct 17 '22 09:10

Shadow Wizard Hates Omicron