asp.net中通过form表单submit提交到后台的实例
来源:互联网 发布:淘宝会员名非法字符 编辑:程序博客网 时间:2024/05/20 01:09
asp.net中通过form表单submit提交到后台的实例
前台<body>中的代码:
<
body
>
<
div
id="top"> </
div
>
<
form
id="login" name="login" action="?Action=Login" method="post">
<
div
id="center">
<
div
id="center_left"></
div
>
<
div
id="center_middle">
<
div
class="user">
<
label
>用户名:
<
input
type="text" name="UserName" id="UserName" />
</
label
>
</
div
>
<
br
/>
<
div
class="user">
<
label
>密 码:
<
input
type="password" name="UserPassword" id="UserPassword" />
</
label
>
</
div
>
</
div
>
<
div
id="center_middle_right"></
div
>
<
div
id="center_submit">
<
div
class="button"> <
img
alt="" id="loginin" src="images/dl.gif" width="57" height="20" onclick="document.login.submit()"/> </
div
>
<
div
class="button"> <
img
alt="" id="loginreset" src="images/cz.gif" width="57" height="20" onclick="document.login.reset()"/> </
div
>
</
div
>
<
div
id="center_right"></
div
>
</
div
>
</
form
>
<
div
id="footer"></
div
>
</
body
>
通过图片的点击事件,执行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中的参数
{
_UserLoginInfo.UserName = Request.Form[
"UserName"
].ToString();
_UserLoginInfo.UserPassword = Request.Form[
"UserPassWord"
].ToString();
string
user =
"select 管理员名称,密码 from T_管理员表 where 管理员名称='"
+ _UserLoginInfo.UserName +
"' and 密码='"
+ _UserLoginInfo.UserPassword +
"'"
;
if
(myData.readDataSet(user).Tables[0].Rows.Count == 1)
{
Response.Redirect(
"Main.aspx"
,
false
);
//防止Response.End 方法终止页的执行
}
else
{
Response.Write(
"<Script Language=JavaScript>alert('密码或用户名错误,请重试!');</Script>"
);
}
}
break
;
}
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
}
0 0
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- 如何通过submit提交form表单获取后台传来的返回值
- [ASP.NET]如何在表单提交(form,submit)后保持select的选择值
- form表单submit提交后台无反应、前端不报错
- jsp form submit 提交到后台的input元素的值中包含之前查询过的内容
- 表单提交中form.action,form.submit()问题
- 表单提交中form.action,form.submit()问题
- 表单提交中form.action,form.submit()问题
- form表单—提交文件到后台
- asp.net form 表单怎样像ASP一样的提交。
- 阻止form表单submit提交
- asp.net 提交表单实例
- ASP.NET+ExtJs4.0+表单提交submit,上传图片到服务器
- 总结:FORM中使用onSubmit="return false"防止表单自动提交,以及submit和button提交表单的区别
- Struts Action 与ActionSupport的区别
- 为什么中国的程序员总被称为码农
- [Android开发]Activity间切换动画の左出右进
- Java中关于原子操作和volatile关键字
- windows 平台下 event 与 mutex的配合使用 模拟posix的条件变量
- asp.net中通过form表单submit提交到后台的实例
- sql 大数据量查询
- cocos2dx3.3开发FlappyBird总结一:背景介绍
- MFC 平直度检测数据转换不成功原因记录
- int main(int argc,char* argv[])详解
- IOS GCD 常用
- quick cocos2dx 组件使用要领
- java参数后面跟三个点是什么意思
- 这是我的第一个博客