Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create User control with name User.ascx

It compiles and run on browser very well in local and network also.

But when i user it in other web application/web site it gives an error below

"Object reference not set to an instance of an object."

This error was on asp:Label control which is in User.ascx control

Bye

Give solution if possible!.......
Posted

I guess the info you provided is not enough to answer your question. This error has nothing to do with the user contrl it self. it is a coding mistake where you havent instantiated one of the objects. If you provide the code snippet it would be more easier to understand.

Regards
Ahsan Sarfraz



Dont forget to mark as answered if the info is usefull.thanks
 
Share this answer
 
v2
Hi,

1. Your user control should be added to page using relative path. Kindly verify that the way you have added the user control to web page uses "relative path" rather than "absolute path".

[NB: A relative path is like "..\Controls\MyControl.ascx"
An absolute path is like "file:///localhost/MyWeb/MyPage" or "C:\Folder1\Folder2\MyPage.ascx"]

2. If you access a label which is defined (hence used)inside the user control then at the time of rendering in web page, it creates hierarchical id for all conttrol, so as for the label you might be accessing. Hence you dont get that label directly accessing the name say "Label1". Either you have to do in FIndControl of user control to get the reference of UserControl then then inside the user control again you need to call FindControl method to access the label.


Let me know if that helps or please post some code snippet where it throws exception.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900