Add some functions to the control. (Can only be viewed in IE)
For example, textbox controls ,,,,
Generally, an attribute is added.CheckcodeAnd added textboxOnkeypressEvent, write the script into a sring ,,
Page. clientscript. registerclientscriptblock (this. GetType (), "key1", scriptstring, true );Execute scripts ,,,
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Web;
Using system. componentmodel;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Namespace my_customwebcontrls
{
[Defaultproperty ("text "),
Toolboxdata ("<{0}: mytextbox runat = 'server' text =''> </{0}: mytextbox> ")]
Public class mytextbox: textbox
{
Public mytextbox ()
{
This. Load + = new eventhandler (mytextbox_load );
}
Public String checkcode {Get; set ;}
Void mytextbox_load (Object sender, eventargs E)
{
If (this. Page. clientscript. isclientscriptblockregistered ("key1 ")){
Return;
}
Page. clientscript. registerclientscriptblock (this. GetType (), "key1", scriptstring, true );
This. Attributes. Add ("onkeypress", "Return checkinput ('" + checkcode + "')");
}
String temp = string. empty;
Public String scriptstring {
Get {
Temp + = "function checkinput (CODE ){";
Temp + = "for (VAR I = 0; I <code. length; I ++ ){";
Temp + = "If (code. charcodeat (I) = event. keycode ){";
Temp + = "Return true ;}}";
Temp + = "Return false ;}";
Return temp;
}
}
}
}