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>