Web Control added in .master control type not found in child page

Posted by turtle on Stack Overflow See other posts from Stack Overflow or by turtle
Published on 2010-06-07T13:13:26Z Indexed on 2010/06/07 13:22 UTC
Read the original article Hit count: 216

Filed under:
|
|

I have a Web Site project, and within it I have a user Web Control defined in an ascx file.

The control is added to the Site.Master, and it shows up correctly on the page and everything is fine.

I need to override some of the control's fields on one of the pages that derive from Site.Master.

// In OnLoad:
MyControlName control = (MyControlName) Page.Master.GetBaseMasterPage().FindControl("controlID"));

The issue is that MyControlName doesn't register as a valid Type on the child page. If I add a second instance of the control to the child page directly, the above works as needed, but if the control isn't placed directly on the page, and instead is only defined in the master page, the type is undefined. The control is not in a namespace, and is defined within the project, so I don't know why it is having such an issue location the appropriate type.

If I put a breakpoint in the OnLoad, the type listed for the control is ASP.my_control_name_ascx, but using that does not work either.

Why can't the child class reference the correct type? Can I fix this?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET