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

前端 未结 3 522
遥遥无期
遥遥无期 2021-01-13 21:15

I had problem triggering server side button click events so I found a solution on the net that I should do something like

  

        
相关标签:
3条回答
  • 2021-01-13 21:53

    Check this article:

    Understanding the JavaScript __doPostBack Function

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

    You usually (in simple scenarios) don't use the method directly - it is internally used by the controls you drop on the page.

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

    0 讨论(0)
  • 2021-01-13 21:55

    The solution might be working but it's not a real fix.. better way will be to find why the button events are not triggering and fix the core of the problem.

    Now to answer your questions.. PostBack is the term used to describe when the form is being submitted (posted) back to the same page. Simple as that.

    Ordinary submit button would have been enough, but part of PostBack is the ability to identify which control triggered it, meaning what button or link was clicked.

    To do such a thing ASP.NET is automatically adding hidden fields to the form and when clicking on element that should cause PostBack, JavaScript code is used to update the values of those hidden fields to the proper values indicating what was clicked - the argument you pass.

    The name Microsoft chose to give to the JS function doing the above is __doPostBack - it's just a name of a function, ordinary JavaScript function that ASP.NET automatically writes to the browser.

    Hope things are bit more clear now.

    0 讨论(0)
  • 2021-01-13 22:07

    simply said, it is used mainly by controls with AutoPostBack property

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

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

    0 讨论(0)
提交回复
热议问题