asp.net the control's name value automatically after the control is built

Source: Internet
Author: User

ASP tutorial. NET build control automatically gets the name value of the control
Convenient with the Tag property of the control

private void Message (Object Sender,eventargs e)
{
PictureBox pic = sender as PictureBox;
String Lblname= ((label) pic.tag). Name;
MessageBox.Show (Lblname);
}
When the control is dynamically generated, specify name, and then locate it:

foreach (Control ct in form1.controls)
{
C # only traverses the child controls of the form and does not traverse the sun control
When a control on a form has child controls, you need to iterate recursively to list all the controls on the form
if (ct.name== "")
{

}
}
}

Instance

PictureBox p = new PictureBox ();
P.name = "P" + i.tostring ();
P.sizemode = System.windows.forms.pictureboxsizemode.stretchimage;
P.imagelocation = @ "D:www.111cn.nethome4.png";
P.size = New System.Drawing.Size (60, 60);
P.location = New System.Drawing.Point (5 * i-60, 50);
P.cursor = System.windows.forms.cursors.hand;
P.doubleclick + + new EventHandler (message);
P.mousemove + = new System.windows.forms.mouseeventhandler (this.mouseo tutorial ver);
P.mouseleave + = new System.EventHandler (this.mouseo tutorial UT);
P.contextmenustrip = CONTEXTMENUSTRIP1;
This.sp_l_r.panel2.controls.add (P);
Label La = new label ();
La.name = "La" + i.tostring ();
La.text = "0000";
La.location = New System.Drawing.Point (50, 120);
                     This.sp_l_r.panel2.controls.add (LA);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.