<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default3.aspx. CS " Inherits = " Webparts_default3 " %>
<% @ Register SRC = " Selectpro. ascx " Tagname = " Selectpro " Tagprefix = " Uc1 " %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > No title page </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div Onclick = 'Test ()' >
< ASP: textbox ID = "Textbox1" Runat = "Server" > </ ASP: textbox >
< ASP: textbox ID = "Textbox2" Runat = "Server" > </ ASP: textbox >
< ASP: textbox ID = "Textbox3" Runat = "Server" > </ ASP: textbox >
< ASP: textbox ID = "Textbox4" Runat = "Server" > </ ASP: textbox >
< ASP: textbox ID = "Textbox5" Runat = "Server" > </ ASP: textbox >
</ Div >
< Script Type = "Text/JavaScript" >
Function Test ()
{
Alert ( ' <% = Textbox1.clientid %> ' );
}
</ Script >
</Form>
</Body>
</Html>
Using System;
Using System. collections;
Using System. configuration;
Using System. Data;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. htmlcontrols;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Public Partial ClassWebparts_default3: system. Web. UI. Page
{
Protected VoidPage_load (ObjectSender, eventargs E)
{
Set1 ();//Or set2 ();
}
Public Void Set1 ()
{
String Script = "" ;
For ( Int I = 0 ; I < Page. Form. Controls. Count; I ++ )
{
If (Page. Form. controls [I] Is Textbox)
{
Textbox txt = Page. Form. controls [I] As Textbox;
TXT. Attributes. Add ( " Onclick " , TXT. clientid + " _ Show () " );
TXT. style. Add (htmltextwriterstyle. backgroundcolor, " Yellow " );
Script + = " Function " + TXT. clientid + " _ Show () {alert (' " + TXT. clientid + " ');}; " ;
}
}
Page. clientscript. registerstartupscript ( This . GetType (), " Script " , " <SCRIPT> " + Script + " </SCRIPT> " );
}
Public Void Set2 ()
{
String Script = "" ;
For ( Int I = 0 ; I < Page. Form. Controls. Count; I ++ )
{
If (Page. Form. controls [I] Is Textbox)
{
Textbox txt = Page. Form. controls [I] As Textbox;
TXT. Attributes. Add ( " Onclick " , " Show (' " + TXT. clientid + " ') " );
TXT. style. Add (htmltextwriterstyle. backgroundcolor, " Red " );
Script = " Function show (ID) {alert (ID );}; " ;
}
}
Page. clientscript. registerstartupscript ( This . GetType (), " Script " , " <SCRIPT> " + Script + " </SCRIPT> " );
}
}