开发者

Web user control loses properties on postback

I created a usercontrol that has a public event named "DialogClosed".

This usercontrol also have a button. When the user clicks on the button, the background code fires the "DialogClosed" event.

The problem is that after the user clicked on the button, it caused to postback, which created a new instance of my control, and my control los开发者_JAVA百科t all his properties because the original instance no longer exist.

So when I fire the event, it throws an exception (because "DialogClosed" == null)


Maybe I'm missing something...but couldn't you just check against the IsPostback property of the page when you create the control, to ensure the control is not created on a postback?

Also, in what event are you creating the control?


Is ViewState enabled for the control?

If it is, the UserControl needs to be instantiated on the page's Init Event so the properties are persisted on a post back, unless you've simply declared it in the aspx markup.


you need to re-bind the event handler after the page is post back. but the properties should not be lost if viewstate is enabled.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜