Asp.net automatically obtains the control name after the control is generated.

Source: Internet
Author: User

Asp tutorial. net automatically obtains the control name value after the control is generated
// Convenient to use the tag attribute of the control

Private void message (object sender, eventargs e)
{
Picturebox pic = sender as picturebox;
String lblname = (label) pic. tag). name;
Messagebox. show (lblname );
}
// Specify the name when dynamically generating the control and find it:

Foreach (control ct in form1.controls)
{
// C # Only traverse the child control of the form, not the child Control
// When the controls on the form have subcontrols, You need to traverse them recursively to list all 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.bKjia.c0mhome4.png ";
P. size = new system. drawing. size (60, 60 );
P. location = new system. drawing. point (5*17 * 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 );

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.