After dynamically adding controls in the background, the script cannot obtain the Control ID.

Source: Internet
Author: User

 

After the control is dynamically added to the background, the script cannot obtain the ID of the control. You must obtain the ID using the above method.

BackgroundCode:

Public void bindnotmaincategory ()
{
Dataset DS = lifeexpress. components. poicategory. getchildcategorydataset (0 );
Notnotmaincategoryidlist. Text = ""; // enter a value in the input box.

For (INT I = 0; I <Ds. Tables [0]. Rows. Count; I ++)
{

Checkbox WPS = new checkbox ();
WPS. ID = "Chk" + Ds. Tables [0]. Rows [I] ["ID"]. tostring ();
WPS. tooltip = Ds. Tables [0]. Rows [I] ["ID"]. tostring ();
WPS. Text = Ds. Tables [0]. Rows [I] ["displayname"]. tostring ();
Panelnotmaincategory. Controls. Add (WPs); // panelnotmaincategory is a panel control

Checkboxlist chklist = new checkboxlist ();
Chklist. repeatdirection = repeatdirection. horizontal;
Chklist. ID = WPS. tooltip;
Chklist. repeatcolumns = 4;
Dataset ds1 = lifeexpress. components. poicategory. getchildcategorydataset (convert. toint32 (WPS. tooltip. Trim ()));
If (ds1.tables [0]. Rows. Count> 0)
{
Chklist. datasource = ds1;
Chklist. datatextfield = "displayname ";
Chklist. datavaluefield = "ID ";
Chklist. databind ();
If (! Panelnotmainchildcategory. Controls. Contains (chklist ))
{
Panelnotmainchildcategory. Controls. Add (chklist); // panelnotmainchildcategory is a panel control.

}
}

// Move the cursor over the control WPS to display the corresponding chklist control and hide other checkboxlist controls.

WPS. Attributes. Add ("onmouseover", "onmouseupnotmaincategory (" + chklist. clientid + ")");
Notnotmaincategoryidlist. Text = notnotmaincategoryidlist. Text + chklist. clientid + ",";

If (I = 0)
{
WPS. Checked = true;
// Chklist. Visible = true;
Chklist. style. Add ("display", "Block"); // whether to use the style Control for display and hide, without vislble.
}
Else
{
// Chklist. Visible = false;
Chklist. style. Add ("display", "NONE ");
}
}
If (notnotmaincategoryidlist. Text. length> 0)
{
Notnotmaincategoryidlist. Text = notnotmaincategoryidlist. Text. substring (0, notnotnotmaincategoryidlist. Text. Length-1 );
}
}

Front-end code

<SCRIPT>

 

Function onmouseupnotmaincategory (ID)
{

// ID. style. Display = "Block"; control to be displayed
// Notnotmaincategoryidlist is a file box that stores the ID list. Notnotmaincategoryidlist is a drag-and-drop control. You can use document. getelementbyid ('<% = notnotmaincategoryidlist. clientid %>') to obtain the control.
VaR idlist = Document. getelementbyid ('<% = notnotmaincategoryidlist. clientid %> ');
Repeated r = idlist. value. Split (',');
For (I = 0; I <strong R. length; I ++)
{
If (document. getelementbyid (direction R [I])! = ID)
{
Document. getelementbyid (mirror R [I]). style. Display = "NONE ";
}
Else
{
Document. getelementbyid (mirror R [I]). style. Display = "Block ";
}
}
}

</SCRIPT>

 

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.