前台<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="data:images/dl.gif" width="57" height="20" onclick="document.login.submit()"/> </div>
<div class="button"> <img alt="" id="loginreset" src="data: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[].Rows.Count == )
{
Response.Redirect("Main.aspx", false);//防止Response.End 方法终止页的执行
}
else
{
Response.Write("<Script Language=JavaScript>alert('密码或用户名错误,请重试!');</Script>"); }
}
break;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

asp.net中通过form表单submit提交到后台的实例的更多相关文章

  1. 基于form表单submit提交不跳转

    方法一:target <html> <body> <form action="" method="post" target=&qu ...

  2. jQuery动态创建form表单并提交到后台(携带一定的数据进行页面跳转)

    今天遇到这么一个需求,携带一个编号一个名字跳转到另一个JSP页面,直接页面跳转(get携带数据)的话不太安全,于是想到到后台转发一下. 第一种:直接以表单提交方式的进行 JS代码: var form ...

  3. jQuery Ajax 确定 form 表单 submit 提交成功

    使用 jQuery 提交表单,可以使用 同步方式(async: false). a.html 是 html 文件,a.php 是服务端文件,把 a.html 中表单的数据提交到 a.php 中,在提交 ...

  4. JS将文件以form表单一样提交到后台

    这是很简单.. HTML <div> <input type="file" id="myfile"> <input type=&q ...

  5. JS将文件像form表单一样提交到后台

    这是很简单.. HTML <div> <input type="file" id="myfile"> <input type=&q ...

  6. Javascript中的Form表单知识点总结

    Javascript中的Form表单知识点总结 在HTML中,表单是由form元素来表示的,但是在javascript中,表单则由HTMLFormElement类型,此元素继承了HTMLElement ...

  7. django中的 form 表单操作

     form组件  1. 能做什么事?   1. 能生成HTML代码  input框   2. 可以校验数据   3. 保留输入的数据   4. 有错误的提示   1. 定义   from django ...

  8. form表单submit按钮提交页面不跳转

    方案一 <html> <body> <form action="" method="post" target="nm_i ...

  9. form表单submit事件

    form表单submit事件同时会触发form表单中button按钮的click事件 <!DOCTYPE html> <html> <head> <meta ...

随机推荐

  1. swoole_http_server客户端测试

    测试方法: http_server.php 文件内容 <?php // use Swoole\Http\Server; // $http = new Server("0.0.0.0&q ...

  2. RTMP协议的理解

    RTMP协议:real time message protocol 工作原理: 先采集摄像头视频和麦克风音频信息,再进行音视频的编码(mpeg),通过FMLE(Flash Media Live Enc ...

  3. hdu-5753 Permutation Bo(概率期望)

    题目链接: Permutation Bo Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/ ...

  4. Python:深浅拷贝

    导入模块: >>> import copy 深浅拷贝: >>> X = copy.copy(Y) #浅拷贝:只拷贝顶级的对象,或者说:父级对象 >>&g ...

  5. [练习]使用dx.bat、dexdump.exe、javap、Baksmali

    PART0 这几个工具的关系可以这样描述: 用例: public class Hello { public int foo(int a , int b ) { return (a+b) * (a-b) ...

  6. 装饰器 decorator

    装饰器 def document_it(func): def new_function(*args, **kwargs): print('Running function:', func.__name ...

  7. vue 使用scss报错

    vue-cli默认没有scss-loader,需要安装依赖:sass-loader  node-sass 安装之后重启就可以使用: <style lang="scss"> ...

  8. web缓存概述

    缓存无处不在,所展示出的仅仅是服务器端的缓存,我们从细节层面一层层分析 但是在此之前,我们先要知道什么是缓存与为什么要使用缓存,是时候百度一波喽~ 缓存就是数据交换的缓冲区(称作Cache),当某一硬 ...

  9. AngularJS系统学习之Directive(指令)

    本文转自https://www.w3ctech.com/topic/1612 原文作者: Nicolas Bevacqua 原文:AngularJS’ Internals In Depth, Part ...

  10. Can you answer these queries II

    题意: 给一长度为n的序列,有m组询问,每一组询问给出[l,r]询问区间内的最大去重连续子段和. 解法: 考虑一下简化后的问题:如果题目要求询问查询以$r$为右端点且$l$大于等于给定值的去重连续子段 ...