ASP.NET对象有以下几个:
本文从“asp.net中经由过程from表单submit提交到背景的实例”来谈谈Request和Response这两个对象的应用。
(一)引入实例
前台<body>中的表单代码:
<body> <form method="get" action="WebForm1.aspx"> <table style="width:50%;"> <tr> <td> </td> <td> <input id="text1" name="txtUserName" type="text" /></td> <td class="auto-style1"> </td> </tr> <tr> <td> </td> <td> <input id="text2" name="txtUserPwd" type="text" /></td> <td class="auto-style1"> </td> </tr> <tr> <td> </td> <td> <input id="ccc" type="submit" value="提交" /></td> <td class="auto-style1"> </td> </tr> </table> </form> </body>
表单中的method要领,即表单的提交要领。
表单中的action要领,指定表单的提交目的。
action=“WebFrom1”,指的是表单的提交后指向WebForm1窗体。在该途径的页面中,用Request.From能够接收到Post要领的数据。用Requet.QuestString能够接收Get的数据。细致用Post照样用Get,能够在表单中的Method属性中设置。
背景的C#代码:
public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Request三种猎取表单值得要领。 #region 关于post要领递交表单的猎取值要领 //string userName = Request.Form.Get("txtUserName").ToString(); //string userPwd = Request.Form.Get("txtUserPwd").ToString(); #endregion #region 关于get要领递交表单的猎取值要领 //string userName = Request.QueryString["txtUserName"].ToString(); //string userPwd = Request.QueryString["txtUserPwd"].ToString(); #endregion #region 对二者要领都实用的要领,应用Reuqest的索引值去猎取所请求的表单值 string userName = Request["txtUserName"].ToString(); string userPwd = Request["txtUserPwd"].ToString(); #endregion Response.Write("上岸的用户名为:" + userName + ";暗码为:" + userPwd); if (userName=="a"&&userPwd=="b") { Response.Redirect("WebForm2.aspx"); } else { Response.Redirect("login.html"); } } }
(二)Request对象和Response对象用法总结
一、Request对象:
Request三种猎取表单值得要领的细致完成,我已都写入到子女代码的实例中了,在这里就不赘述。
这里须要注重的是:get和post要领的区分以下:
get要领提交,直接定义一个url就能够传值。瑕玷是,传的值是明码显现的。由于浏览器显现的字符是有长度的,所以他的数据显现的时刻是受限制的。
post提交,是把数据作为一个全部鸠合举行提交,关于post要领传值的要领传的参数不会在url顶用明码显现。
二、Response对象
response对象,最主要的用到的要领是respone.write(string)和responst.redirect(url).
response.write(string)的作用是从服务器端向客户端返回数据(写数据)。
response.rediec("url")的作用是在服务器端重定向另一个网页。
【相干引荐】
1. 总结Asp.net内置对象之Request对象应用实例
2. 分享一个Request对象小案例
3. 分享asp中request对象五个猎取客户端材料的要领
4. 详解ASP.NET 体系对象之Request
以上就是谈谈Request和Response这两个对象的应用的细致内容,更多请关注ki4网别的相干文章!