如何从html表单中的Post方法读取数据到另一个aspx页面 [英] How to read data from Post method in html form to another aspx page

查看:70
本文介绍了如何从html表单中的Post方法读取数据到另一个aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有1个html表单,其中包含名称性别和城市的输入文本框。现在我希望在使用post方法向此方法重定向数据的表单提交表单后,可以在另一个aspx页面的Page load上访问此数据。怎么做?



我尝试在aspx页面页面加载代码



string name = Request。表格[用户名];

Label1.text = name;



以上代码无效

Hi ,
I have 1 html form in that have input text box for name gender and city. Now i want this data to be accessible on Page load of another aspx page after submitting the form with post method to which this Post method redirect data. How to do it?

I tried following code on aspx page pageload

string name=Request.Form["username"];
Label1.text=name;

above code is not working

推荐答案

是的,因为Request.Form仅适用于当前页面,表单已提交数据,一旦你在下一页,你松开这个Form属性,你有一个Request类,你可以调用Form数据作为Request本身的一个元素。



像这样,



Yes, because Request.Form only works on the current page, where the Form has submitted the data on, once you're on the next page, you loose this Form property, you have a Request class, and you can call the Form data as an element of the Request itself.

Like this,

string name = Request["username"];
// Label1 is a Label, and it has only 'Text' method
// and not a 'text' method. Case sensitive
Label1.Text = name; 





您可以运行此代码,它将从请求中获取用户名元素的值。



请确保输入字段的名称是用户名


Html页面代码..



Html page code..

<form action="HtmlToAspx.aspx" method="post">
       <div class="body bg-gray">
           <div class="form-group">
               <input type="text" name="userid" class="form-control" placeholder="User ID"/>
           </div>
           <div class="form-group">
               <input type="password" name="password" class="form-control" placeholder="Password"/>
           </div>
           <div class="form-group">
               <input type="checkbox" name="remember_me"/> Remember me
           </div>
       </div>
       <div class="footer">
           <button type="submit" class="btn bg-olive btn-block">Sign me in</button>

           <p><a href="#">I forgot my password</a></p>

           <a href="register.html" class="text-center">Register a new membership</a>
       </div>
   </form>





重定向页面HtmlToAspx.aspx代码..





Redirect page HtmlToAspx.aspx Code..

if (!IsPostBack)
        {
            string name = Request.Form["userid"];
            Response.Write(name);







And the code Working Fine..


这篇关于如何从html表单中的Post方法读取数据到另一个aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆