Why doesn't this button trigger a triple postback?

We developed a page with asp.net and we are debugging it by accident, we found on our page a button with the following onclik attribute code

onclick="__doPostBack('ctl00$FormPlace$m_userTaskMarkAsUnreadButton',''); __doPostBack('ctl00$FormPlace$m_userTaskMarkAsUnreadButton','');WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$FormPlace$m_userTaskMarkAsUnreadButton", "", true, "", "", false, false))"

      

The button seems to do three postbacks, but when we click on it, it only triggers the postback. With this code, it looks like the button will trigger three postbacks.

We'll try it with Internet Explorer and Firefox, and the button always triggers a postback. Will browsers avoid the button doing three postbacks? Or an Asp.net server that avoids three postbacks? We don't understand why the button behaves correctly if the onclick attribute has three calls to make Postbacks.

thanks

+2


a source to share


4 answers


If the first JavaScript function called causes the page to POST your data (not using XMLHttpRequest), a new page is loaded and your JavaScript execution stops.



+5


a source


The first __doPostback will immediately publish the page. The other two statements will never be executed.



+3


a source


__ doPostBack fills in two hidden fields with the specified parameters, and then sends it to the server. Anything that comes later in javascript doesn't matter because the page will be destroyed and rebuilt.

+3


a source


I know I'm reinventing the wheel here ... but __doPostBack actually .. does a postback , so when the first __doPostBack is executed, the youre on page has already gone.

And btw, doing it like this sounds very tricky. Why not call one method and do it 3 times in the background?

Also .. depends on whether you are using UpdatePanels ..

+1


a source







All Articles