Thursday, August 23, 2007

Loading Controls Dynamically problem on ASP.Net 2.0

Hi Folks,

If you load your controls dynamically on 2.0 web site,you will face a problem that all handlers of server side controls doesn't work and not fire on the server side.

Even you try to put a break point on your server side handler,it will not fire,this is not because of a problem on any of your user controls or your code has something wrong.

the problem is : if you try to write the same line of code on 1.1 web application this problem will not happen at all,and if you tru to load the same controls on 2.0 web site the problem will happen.

The solution and Tip for this problem,is to just give an ID for your user control which will be loaded dyamiccly,and the problem will not happen.

This the code which run on 1.1 perfectly and doesnt run on website :

Control c = Page.LoadControl(”UCPath”);

The Solution :
Control c = Page.LoadControl(”UCPat”);
c.ID = “IDForYourControl“;

Hope this helps.

Read more on the problem and the solution on Scott Blog :

Moustafa arafa
Post a Comment