Custom properties in a User Control at Design time

N

Nathan Bidwell

I have a user control I'm using to wrap the content of all pages on a
site. I've successfully added a template property which will correctly
render anything inside of it. The resulting aspx looks something like this:
<%@ Page language="c#" Codebehind="wrapTest.aspx.cs"
AutoEventWireup="false" Inherits="test.wrapTest" %>
<%@ Register TagPrefix="uc1" TagName="wrapper"
Src="controls/wrapper.ascx" %>
<uc1:wrapper id="Wrapper" runat="server">
<Title>A Test Page</Title>
<Content>
<asp:label runat="server" id="foo" Text="bar" />
</Content>
</uc1:wrapper>

The problem is that Visual Studio's design view becomes useless with the
message "Parser Error: Type 'System.Web.UI.UserControl' does not have a
property named 'Title'." What I don't understand is why the designer
doesn't pick up the derived UserControl type of 'wrapper'.

Any help would be appreciated.

Nathan
 
M

Michael Tkachev

Hi,

You have this problem because your custom control does not have a public
ptoperty Title
You have to create a public property E.g:

--------------- yourControl.cs ---------------
public string Title
{
set
{
_Title = value;
}
}

private string _Title;

--------------- End yourControl.cs ---------------


Bye

The Best Regards,
Web Developer
Michael Tkachev
 
N

Nathan Bidwell

Unfortunately, I do have a public property which the designer just
doesn't see correctly. The code compiles and runs correctly, it's just
Visual Studio's designer view that gets confused.

protected PlaceHolder title;
public ITemplate Title
{
set
{
value.InstantiateIn(title);
}
}

Thank you

Nathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top