Web User Control

D

Dave

Hello.
I have created some WebUserControl where I put some label, then I put this
WebUserControl on my page and now I want to change label text on
WebUserControl from my page, but I can't access it from my C# code (the
WebUserControl id is Control1).
May be I must insert runat="server" tag? But where?
So, how can I do this?
 
W

wh1974

You'll need to insert the runat='server' tag to your web control in the
..aspx file:

<test:mycontrol id="MyControl" runat="server" />

remember to add the @register directive to the top of the page containing
your webcontrol.

Next, in the code-behind for the page, add a declaration for your control:

protected MyControlClass MyControl;

You'll then be able to programatically access the control using the
'MyControl' variable.

Wayne.
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top