Tuesday, October 6, 2009

LoadControl problem in ASP.Net

Today I met a problem and it made me angry enough to make some dumb checks and found an interesting thing conecrning the runtime control loading. I was trying to load controls using the LoadControl method in this way (using this overload of the method): LoadControl(type, object[]). This seemed ok - the control is being instanciated but when I was trying to access a property of it - found that all the inner controls were not loaded and I was getting NullReferenceException.
And here was the solution - seems that the LoadControl(string) overload works much more better and using this overload you can get the required control with all its properties initialized.
Good luck.

No comments: