当前位置:文档之家› asp_net中通过form表单submit提交到后台的实例+

asp_net中通过form表单submit提交到后台的实例+

中通过form表单submit提交到后台的实例

form

中通过form表单submit提交到后台的实例

前台中的代码:

id="top">

method="post">

name="UserName" id="UserName" />


name="UserPassword" id="UserPassword" />

id="loginin" src="images/dl.gif" width="57" height="20"

onclick="document.login.submit()"/>

id="loginreset" src="images/cz.gif" width="57" height="20"

onclick="document.login.reset()"/>

通过图片的点击事件,执行form.submit()传递form中的参数。

后台cs代码:

protected string Action = "";

myBaseClass myData = new myBaseClass();

protected class UserLoginInfo

{

public string UserName = "";

public string UserPassword = "";

}

protected UserLoginInfo _UserLoginInfo = new UserLoginInfo();//创建对象

protected void Page_Load(object sender, EventArgs e)

{

Init_WebControls();

}

public void Init_WebControls()

{

try

{

if (!string.IsNullOrEmpty(Request.QueryString["Action"]))//获取form的Action中的参数

{

Action = Request.QueryString["Action"].Trim().ToLower();//去掉空格并变小写

}

switch (Action)

{

case "login":

if (!string.IsNullOrEmpty(Request.Form["UserName"])

&& !string.IsNullOrEmpty(Request.Form["UserPassWord"]))//获取form中的参数

{

_erName =

Request.Form["UserName"].ToString();

_erPassword =

Request.Form["UserPassWord"].ToString();

string user = "select 管理员名称,密码 from T_管理员表 where 管理员名称='" + _erName + "' and 密码='" + _erPassword

+ "'";

if (myData.readDataSet(user).Tables[0].Rows.Count

== 1)

{

Response.Redirect("Main.aspx", false);//防止Response.End 方法终止页的执行

}

else

{

Response.Write("");

}

}

break;

}

}

catch (Exception ex)

{

throw new Exception(ex.Message);

}

}

相关主题