[ASP.net C#]如何接收在同一网站的其他页面中发布的表单数据 [英] [ASP.net C#] How do I receive form data which was posted in another page in the same website

查看:74
本文介绍了[ASP.net C#]如何接收在同一网站的其他页面中发布的表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个html网页( form.html ),其中包含一个使用POST方法发送的简单表单:

Let's say I have one html web-page (form.html) containing a simple form which is sent using POST method:

<body>
   <form name="Form1" method="POST" action="process.aspx">
      <input name="firstname" type="text" value="" />
      <input name="lastname" type="text" value="" />
      <input type="submit" value="Send" name="submit" />
   </form>
</body>





现在,在同一目录( process.aspx )的另一个页面中,我想以某种方式处理数据。我如何获取此数据?我试图做的是:



Now, in another page at the same directory (process.aspx) I want to process the data in some way. How do I fetch this data? What I tried to do is:

string firstname = Request.Form["firstname"];
string lastname = Request.Form["lastname"];





它不起作用。这样做的正确方法是什么?



It didn't work. What's the right way to do this?

推荐答案

参考 - 阅读发布数据提交给ASP.Net表格 [ ^ ]

Refer - Read Post Data submitted to ASP.Net Form[^]
Quote:

读取Request.Form NameValueCollection并相应地处理你的逻辑:



Read the Request.Form NameValueCollection and process your logic accordingly:

NameValueCollection nvc = Request.Form;
string userName, password;
if (!string.IsNullOrEmpty(nvc["txtUserName"]))
{
  userName = nvc["txtUserName"];
}

if (!string.IsNullOrEmpty(nvc["txtPassword"]))
{
  password = nvc["txtPassword"];
}

//Process login
CheckLogin(userName, password);



...其中txtUserName和txtPassword是发布页面上控件的名称


string firstname = HttpContext.Current.Request["firstname"];


or

string firstname = Request.Form["firstname"];


这篇关于[ASP.net C#]如何接收在同一网站的其他页面中发布的表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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