How to pass values into a user control

T

Tony

I've created a user control in C# with a Title Property

I can set up the title in HTML by passing the title property as shown

<uc1:USRTitle id="myTitle" runat="server" Title="This is the
Title"></uc1:AdminTitle>

But what I really want to do is pass this value from the Page Load event ie:

myTitle.Title = "Hello Title"

but the Title property (although public) is not exposed on the control at
this point - How do I do this?
Thanks
 
J

Jos

Tony said:
I've created a user control in C# with a Title Property

I can set up the title in HTML by passing the title property as shown

<uc1:USRTitle id="myTitle" runat="server" Title="This is the
Title"></uc1:AdminTitle>

But what I really want to do is pass this value from the Page Load
event ie:

myTitle.Title = "Hello Title"

but the Title property (although public) is not exposed on the
control at this point - How do I do this?

It should be exposed.

Are you using codebehind? If so, is there an instance
of the user control as a member in the Page class?
 
T

Tony

Ah - I manually created an instance of the control and it all works - I
wonder why it wasnt there automatically!
Thanks
 
R

rohan_p

I often find that this does not happen - there's a KB article regarding the
problem - it just advises you to create the reference manually.
 
S

Scott Mitchell [MVP]

Tony said:
Ah - I manually created an instance of the control and it all works - I
wonder why it wasnt there automatically!

ASP.NET User Controls aren't added to the code behind class
automatically, like other Web controls. At least not in ASP.NET 1.x...
in 2.0 everything works like it should. :-/


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top