R – Web user control loses properties on postback

asp.netcontrols

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 lost all his properties because the original instance no longer exist.

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

Best Answer

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?

Related Topic