Set the CHECKBACKOPOSTBACK OTOPOSTBACK attribute of the template column to True, because the controls in the template column have no events, so write an event program in the ASPX page, and set the checkbox's oncheckedchanged event to the required event program. Examples are as follows:
Void Check_change (Object Sender, Eventargs E)
{
TextBox TXTDESCRIPTION;
Foreach (DataGridItem Item in itemsgrid.Items)
{
Selection = (Checkbox) Item.FindControl ("chubenabled");
TXTDESCRIPTION = (TextBox) Item.FindControl ("TXTDESCRIPTION");
IF (selection.checked) {txtdescription.enabled = false;
Else {txtdescription.enabled = true;
}
}
Thus, when Checkbox is selected, the contents in the TextBox will not be editable, and the defect of this example is that it is not intended to be flexible in JavaScript because each time you communicate with the server each time.
ASP.NET to implement Web controls for verification code features
ASP.NET design and design concepts and others such as ASP, JSP, PHP, Perl
Almost different, almost completely object-oriented design! The multiplexing of the code is
One of the large differences in the difference, ASP.NET is available in addition to include in Include
Amazing web control, including: ASCX form and controlled control
This article belongs to the latter], in order to familiarize yourself with these new concepts, I wrote a web control.
It will continue to improve in the actual project.
How to use the ValidateCode control:
first step:
Compile I provide the original code, then on the Studio.Net 2003 toolbar, select Add / Transfer (Subscription ", select the compiled DLL file.
Step 2:
There will be more web control validatecode on the toolbar, do a web form, on the Studio.Net 2003 development interface, drag the control directly to Webform, OK!
third step:
Get the character information of the verification code in the Graphicok event of the control, it is compared to the user!
last step:
Under the root of the website, build a TEMP directory (you can also specify your own directory), used to store the verification code
Image, don't worry, the code will automatically delete the useless picture!
The original code is as follows:
using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.IO; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging;
Namespace WebValidatecode {///
Private graphictype pcharttype; private stringpauthencode;
private string pTempImageURLPath = "/ temp"; private string pAuthenImageFullname; private string pAuthenImageFullURL; // check code generating variable start private Bitmap validateImage; private Graphics g; // check code generating variable End
Private textbox txt = new textbox (); private system.web.ui.webcontrols.image img = new system.web.ui.webcontrols.image ();
#REGON Defines Control Event Public Delegate Void Graphiccreated (Object Sender, Eventargs E); Public Event EventHandler Graphicok; // Triggered after the check image generation
Protected Virtual Void ONGRAPHICOK (Object Sender, Eventargs E) {IF (graphicok! = null) {// invokes the delegates. Graphicok (Sender, e);}} #endregion #Region control property // Generate the length of the check code [ Bindable (True), Browsable (TRUE), Category ("Appearance"), DefaultValue (TRUE), Description ("Requires the length of the verification code, it is recommended between 5 ~ 8 digits!")] Public int codelength {get {Return Pcodelen;
Set {pcodelen = value;}}
/ / Generate the length of the check code [Bindable (TRUE), Browsable (True), Category ("Appearance"), DefaultValue (TRUE), Description ("Generates the temporary storage path of the verification code picture, the requirements must be the virtual website Directory! ")] Public string tempimageurlpath {get {return pTEMPIMPIMPIMEURLPATH;
Set {ptempimageurlpath = value;}}
[Bindable (True), Browsable (TRUE), Category ("APPEARANCE"), DefaultValue (GraphiType.jpg), Description ("Select the type of generated checkup file (JPG; GIF; PNG; BMP)!")] Public GraphicType ChartType {get {return pCharttype;
Set {pChartType = value;}}
/ / Generate the width of the code code PUBLIC INT ChartWidth {Get {Return PCHARTWIDTH;
Set {pChartWidth = value;}}
{Get {Return PChartHeight;
Set {pChartHeight = value;}}
/ / Need to generate the check code public string authencode {get {returnparthhencode;}
Set {pauthencode = value;}}
#ndregion
///
Objimage.RenderControl (Output);
///
///
///
ValidateImage = New Bitmap (PCHARTWIDTH, PCHARTHETIGHT, PIXELFORMAT.FORMAT24BPPRGB); // .format24bpprgb); g = graphics.fromimage (validateImage); g.clear (color.lightgray);
//g.drawstring(STRVALIDATECode, New Font ("Song", 16, FontStyle.Bold, New Solidbrush (Color.darkRed), New Pointf (2, 2));
For (int i = 0; i //g.fillRectangle (New Point (0, 0), New Point (120, 30), Color.Fromargb (0, 0, 0), Color.Fromargb (255, 255, 255, 255)), 0, 0, 120, 30); Switch (PCHARTTYPE) {copy graphictype.jpg: validateImage.save (PauthenImageFullname, Imageformat.jpeg); Break; Case GraphicType.gif: ValidateImage.save (PauthenImageFullname, Imageformat.gif); Break; Case graphictype.png: ValidateImage.save (PauthenImageFullname, Imageformat.png); Break; Case GraphicType.bmp: validateImage.Save (pAuthenImageFullname, ImageFormat.Bmp); break; default: validateImage.Save (pAuthenImageFullname, ImageFormat.Jpeg); break;} validateImage.Dispose (); g.Dispose ();} /// / / Define the number of digits for the verification code according to the length required by the user (INT i = 0; I /// try {DirectoryInfo Dinfo = new DirectoryInfo (this.Page.MapPath (pTempImageURLPath)); FileInfo [] FileSet; if (Dinfo.Exists) {switch (pChartType) {case GraphicType.Jpg: FileSet = Dinfo.GetFiles ( "* jpg. "); Break; Case GraphicType.gif: FileSet = DINFO.GETFILES (" *. GIF "); Break; Case graphictype.png: FileSet = DINFO.GETFILES ("*. PNG"); Break; Case GraphicType.bmp: FileSet = DINFO.GETFILES ("*. BMP"); break; default: fileset = dinfo.getfiles ("*. Jpg"); Break;} Foreach (fileInfo fileInfo in fileset) {if (fileinfo.exists) {datetime dts = datetime.now; datetime dtc = fileinfo.creationTIME; Timespan TS = DTS-DTC; IF (ts.seconds> 20) {fileInfo.delete ();}}}} Return true;} catch (ioexception ie) {returnif value;}}}} DataGrid Web Control Basic Operation DGCategory is a DataGrid for displaying the category table Automatic Page: AllowPaging = true !!!! Private void DGCategory_pageIndexchanged (Object Source, System.Web.ui.WebControls.DataGridPageChangeDeventargs E) { DGCategory.currentPageIndex = E.NEWPAGEINDEX; DGCategory.DATABIND (); } Sort: Default Press "PKID" Sort Private void DGCategory_sortcommand (Object Source, System.Web.ui.WebControls.DataGridsortCommandEventArgs E) { String Sortorder = E.Sortexpression.toString (); Binddata (Sortorder); } Private Void Binddata (String Sortorder) { ProductSystem Productsys = new productSystem (); // underlying data interface CategoryData categoryset = productsys.getcategories (1); // underlying data interface, return ID to 1 Category DataView categoryview = categoryset.tables [categoryData.categories_table] .defaultview; categoryview.sort = sortorder; Lbltitle.Text = "Press" Sortorder "Sort"; DGCategory.DataSource = CategoryView; DGCategory.DATABIND (); } Private Void Page_Load (Object Sender, System.EventArgs E) { Binddata ("pkid"); } Edit, update, cancel: Private void DGCategory_EditCommand (Object Source, System.Web.ui.WebControls.DataGridCommandeventArgs E) { DGCategory.editItemIndex = E.Item.itemindex; Binddata ("pkid"); } Private void DGCategory_cancelcommand (Object Source, System.Web.ui.WebControls.DataGridCommandEventArgs E) { DGCategory.editItemIndex = -1; Binddata ("pkid"); } Private void DGCategory_UpdateCommand (Object Source, System.Web.ui.WebControls.DataGridCommandeventArgs E) { String strune = ""; Strupdate = "pkid = '" ((TextBox) E.Item.cells [1] .controls [0]). Text "'"; Strupdate = "ParentID = '" ((TextBox) E.Item.cells [2] .controls [0]). Text "'"; Strupdate = "description = '" ((TextBox) E.Item.cells [3] .controls [0]). Text "'"; Strupdate = "isleaf = '" ((textbox) E.Item.cells [4] .controls [0]). Text "'"; Try { CagegorySet.executeUpdate (STRUPDATE); / / Need to provide updated interfaces in the background DGCategory.editItemIndex = -1; } Catch {