开发者

What is the correct way to use an updatepanel to increment a value in asp.net

If you have an update panel, that displays a number in its Load method, and a button as a trigger, and you make the button have an onclick method that increments the number, the update panel will not update when you click it.

This is because the update panels Load method runs before the OnClick method, so it dra开发者_JAVA技巧ws the number on the screen before it increments it.

At the moment I get around this by using the scriptmanager to tell me which button or whatever caused the update panel to trigger, and then I use that to run the increment method before it renders, which works.

It sucks though because it renders onclick methods for buttons obselete if you want immediate feedback from them, and fills your load method with IF statements.

Am I missing something or is this the intended way update panels work?


That's just the order of the events in the page cycle, and that is the same regardless if you are using update panels or not.

You can use the Page_PreRender event instead to put the number in the page. It occurs after the click event but before the page is rendered as HTML.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜