User control event/viewstate missing during postback

User control event/viewstate missing during postback

Question : Some of your web control's events goes missing or cannot be caught when you load it in a user control?


Always use the Control.UniqueID generated for you by ASP.Net when assigning it to a NAME property of your control.

The complete Control.UniqueId is available when you assess this in OnPreRender stage.

Check your Control.UniqueID which is render into the NAME property of your control on a HTML page. ASP.Net keeps track of the control using Control.UniqueID which makes events / viewstate works.

If you override your UniqueID (for javascript manipulation) you might get this problem.

Why does it work on your Page but not in user control?

On a page, when your control is renders, it probably use name like “MyControl” but in user control this is automatically change to “ctl$_MyControl”. ASP.Net is no longer able to resolve your control id if you override your Control.ID. For example, I created a control and this is what I did.

public override string UniqueID



return this.ID;

} }

This works fine on a Page but when it is loaded on a UserControl, events are not firing and viewstate goes missing as well.

Please read this toooo .. .


Popular posts from this blog

ionic2 cordova build android - Unable resolve gradle 2.2.3

A quick tutorial for OWASP ZAP tool for beginners

OpenCover code coverage for .Net Core