Tutorial :disable usercontrol


How to disable a usercontrol so that the Page_Load is not executed ? Enabled doesn't exist for a usercontrol and Visible doesn't work, it just hide the usercontrol , but the page load is executed.


Do this:

Add this to the top of the page <%@ Reference Control="~/MyControl.ascx" %>

Then when you need the control just add it where you want it like this


This way the control will be only loaded when you need it.


You may be able to remove the control before rendering starts with this.Controls.Remove(xxx) in preInit but you would want to make this happen consistently. E.G. if you remove a control when you first service the request and then let it be enabled on postback you may have a problem deserializing viewstate. maybe. is worth a shot

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »