Subject: User Control Id not working
Posted By: duncanthescott Post Date: 9/22/2003 4:41:58 PM
I created a user control (ascx file) consisting of a panel and a few text boxes.  After placing the control on a web form (aspx file), I cannot reference it in the codebehind file.  I receive the error "Name wucPersonalInfo1 is not declared."  If I run the application anyway, I receive the following runtime error: "Could not load type 'wucPersonalInfo'." The ascx file is in the same project as the aspx file.  Nothing has been compiled yet.

Any ideas?

Thanks, Brandon

Reply By: Jim Rogers Reply Date: 9/22/2003 6:26:50 PM
duncanthescott:

You probably need to add a reference to your ascx file in your aspx project.  Select the Project menu >> select Add Reference >> select Projects tab >> click Browse, find and select your ascx file, then click OK.  Your project aspx should now recognize your ascx file.
Reply By: duncanthescott Reply Date: 9/23/2003 9:04:37 AM
Jim,

Thanks for the suggestion, but the ascx file is contained within the project.

Reply By: planoie Reply Date: 9/23/2003 10:14:15 AM
Can you post your code for the ASPX?  

Do you have a "@ Register" directive on the page?

Peter
Reply By: Imar Reply Date: 9/23/2003 11:44:11 AM
There is a bug in VS.NET. It doesn't add a declaration for a user control to the code behind when you add it. It does so for other controls like text boxes etc.

Manually add the following code to the top of your Class definition (near the other Controls).


Protected Your.Name.Space.YourControl YourControl1

By default, the VS.NET adds YourControl1 as the ID for a user control called YourControl. Make sure that the name of the control matched the code in the Code Behind.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

Go to topic 4460

Return to index page 1040
Return to index page 1039
Return to index page 1038
Return to index page 1037
Return to index page 1036
Return to index page 1035
Return to index page 1034
Return to index page 1033
Return to index page 1032
Return to index page 1031