Write a user control for landing.

xiaoxiao2021-03-06  110

In the ASCX file, put the TextBox control, as the input of the user and the password, and then put it into imagebutton, other few more other

Codebehind page:

Namespace gst.ui {using system.data; using system.drawing; using system.web; using system.web.ui.webcontrols; using system.web.ui.htmlControls;

///

/// User login control /// public class login: system.web.ui.userControl {

// system declared protected System.Web.UI.WebControls.TextBox txtUser; protected System.Web.UI.WebControls.TextBox txtPass; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; protected System.Web.UI.WebControls.ImageButton Imgsubmit; protected system.web.ui.WebControls.RequidFieldValidator RequiredFieldValidator2;

// Declare delegate

Public Delegate Void EventHandler (Object Sender, Logineventargs E); Public Event EventHandler Loginsystem;

Public void onlineinsystem (logineventargs e) {if (loginsystem! = null) {loginsystem (this, e);}}

Private void page_load (object sender, system.eventargs e) {// Place user code here to initialize page //Response.write (this.FindControl ("tuser" ).Unique);}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // initializeComponent (); base.oninit (e);} ///

/// Designer Support required method - Do not use code editor // to modify the contents of this method. /// private void InitializeComponent () {this.imgSubmit.Click = new System.Web.UI.ImageClickEventHandler (this.imgSubmit_Click); this.Load = new System.EventHandler (this.Page_Load);

} #Endregion

Private void imgsubmit_click (object sender, system.web.ui.imageClickeventargs e) {

// trigger event this.onloginsystem (new logineventargs (txtuser.text);}}

///

/// Defines a class /// public class logineventargs that provides login event data: system.eventargs {private string _user; private string _pass;

Public logineventargs (string user, string pass) {_user = user; _pass = pass;

// account attribute public string user {get {return_user;} set {_user = value;}}

// Password property

PUBLIC STRING pass {get {return _pass;} set {_pass = value;

}

ASPX page call

Background code part

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.web.ui.htmlcontrols; using system.enterprises; using gst.purview; using gst.ui; using sysadmin;

Namespace gst.purview {///

/// loginpurview's summary description. /// public class loginpurview: basepage {

/ / Must be declared. Protected ui.login login1;

// Declare Private Void Page_load (Object Sender, System.EventArgs E) {// Place the user code here to initialize the page}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.Load = new System.EventHandler (this.Page_Load); this.Login1.LoginSystem = new GST.UI.Login.EventHandler (Login1_LoginSystem);} #endregion

private void Login1_LoginSystem (object sender, LoginEventArgs e) {this.Sql = "Select Count (*) From tGSTAdmin Where AdminName = '" e.User "'"; try {if (Convert.ToInt32 (DbConn.ExecuteScalar (Sql )) == 0) {responseMSG2 ("user account does not exist");} else {this.sql = "select adminName = '" E.USER "' and adminpass = ' E.Pass "'"; DATATABLE DT = dbconn.executedataTable (this.sql); if (dt.rows.count> 0) {this.Session ["admin"] = E.User; this.Session ["adminguid"] = Dt.Rows [0] [0]; this.dbconn.executesql ("Update Tgstadmin Set srcip = '" Request.userHostaddress "' where adminName = '" E.USER "'"; Response.Redirect ( "Default.aspx");} else {responsemsg2 ("User or Password Error");}}} Catch (Exception EX) {responseError ("error", ex);}}}}

转载请注明原文地址:https://www.9cbs.com/read-125343.html

New Post(0)