ID value passing of user control attributes Dynamically Loaded by Asp.net

Source: Internet
Author: User
Page code:

Arraylist url = new arraylist (); // module path
Arraylist MD = new arraylist (); // module ID

Url = jyoauser. return_rolemodel (role_id, system_id); // return the URL of the module corresponding to the role
MD = jyoauser. return_rolemodel2 (role_id, system_id); // return the ID of the module corresponding to the role

 

For (INT u = 0; U <URL. Count; U ++)
{

Control UC = new control ();
UC = page. loadcontrol (URL [u]. tostring ());

Type ptype = UC. GetType (); // automatically obtains the type of the control to be loaded.

Propertyinfo Pi = ptype. getproperty ("modelid"); // automatically obtain the property of the loaded control. Of course, if the method is ptype. getmethod

Pi. setvalue (UC, MD [u]. tostring (), null); // pass the module id value of the control to the modelid attribute of the control.


Test. Controls. Add (UC );

}

Controls for each presentation module are dynamically loaded from the database
Some code of a control:
Private int _ modelid; Module ID of the control
Public int modelid
{
Get {return this. _ modelid ;}
Set {This. _ modelid = value ;}
}

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.