开发者

Why this button doesn't cause triple postback?

We have developed a page with a asp.net and debugging it accidentally we have discovered on our page button with the next code on onclik attribute

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

It seems that the button do three postbacks but when we click it only cause on postback. With this code seems that de button will cause three postbac开发者_开发问答ks!!

We have try it with Internet Explorer and Firefox and the button only cause on postback always. Are browsers who avoid that the button do three postback ? Or Is Asp.net server who avoid the three postback? We don't understand why the button behaves correctly if onclick attribute has three call to do Postbacks.

Thanks


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


The first __doPostback will post the page immediately. The remaining two statements will never be executed.


__doPostBack fills two hiddenfields with the given parameters and then does a submit to the server. Everything what comes later in the javascript is irrelevant because the page will be destroyed and rebuilded.


I know I’m reinventing the wheel here... but __doPostBack actually.. does postback so when first __doPostBack is executed the page you’re on is already gone.

And btw, doing it that way sounds very dodgy.. why not call one method and do it 3 times in the back-end?

Also.. it depends whether or not you are using UpdatePanels..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜