What is the meaning of the __doPostBack function and when is it used?

I had a problem triggering events on the server side on the server side, so I found a solution on the network that I should do something like

<input type="submit" name="button" id="loginButton" value="Submit" class="button-orange" alt="Register" title="Register" runat = "server" onclick ="this.disabled=true;__doPostBack('loginButton','')"/> 

I did it and it worked, but I would like to know what is going on!

+4
source share
3 answers

just said that it is mainly used by controls with the AutoPostBack property

http://www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx

if you want to implement autorun for your custom control, you need to implement IPostBackDataHandler

+4
source

Check out this article:

Understanding JavaScript __doPostBack

This method is used to submit (submit) the form to the server and allows the ASP.NET framework to call the appropriate event handlers attached to the control that raised the message back.

Usually you (in simple scripts) do not use the method directly - it is internally used by the controls that you throw on the page.

The parameters passed to this function are stored in a hidden field and are picked up by the ASP.NET framework on the server side to find the control that raised the message.

+5
source

The solution may work, but it is not a real solution. The best way would be to find the reasons why the button events do not fire and do not fix the core of the problem.

Now, to answer your questions .. PostBack is a term used to describe when a form is sent (sent) back to the same page. Just like that.

A regular submit button would be enough, but part of PostBack is the ability to determine which control invoked it, which means that a button or link is clicked.

To do such a thing, ASP.NET automatically adds hidden fields to the form and when you click on the element that PostBack should call, JavaScript code is used to update the values ​​of these hidden fields to the correct values ​​indicating what was clicked - the argument you transmit.

The name Microsoft chose for the JS function that runs above is __doPostBack , which is just the name of the function, just a normal JavaScript function that ASP.NET automatically writes to the browser.

Hope that is now more and more clear.

+2
source

Source: https://habr.com/ru/post/1344578/


All Articles