Web User Control

  • Thread starter Thread starter Dave
  • Start date Start date
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?
 
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.
 
Back
Top