Get ID of the control

  • Thread starter Thread starter Green
  • Start date Start date
G

Green

Hi,
I have an user control on one page, how can i get the id of the user
control?

Any idea?

Thanks ahead.
 
Hi,
On server-side use the .ID property itself. For client-side processing
purpose, use the .ClientID property.


Hi,
I have an user control on one page, how can i get the id of the user
control?

Any idea?

Thanks ahead.
 
Hi Green,

As Shiva has mentioned, do you want to access the UserControl at serverside
via its ID or want to do any other things? Generally, if we add the
Usercontrol onto asp.net page at design-time, there will be a certain
control tag for it and the tag has a "id" attribute which just represent
the UserControl's serverside Control ID.
For example:

<uc:UserControl id="myUC" runat="server" ..... ></uc:UserControl>

And thus, we can referene the UserControl at runtime through this ID, for
example:

Page_Load(...)
{
HtmlForm form = Page.FindControl("Form1") as HtmlForm;
UserControl uc = form.FindControl("myUC") as Usercontrol;

if(uc != null)
{
//.....
}
}

If you have any other questions, please feel free to post here.Thanks.


Regards,

Steven Cheng
Microsoft Online Support
 
Back
Top