Asp.net 返回空请求的简单HTTP Post。表单

Asp.net 返回空请求的简单HTTP Post。表单,asp.net,http-post,Asp.net,Http Post,我正在尝试一个简单的HTTP post,以便在asp.net中将数据从一个表单发布到另一个表单。 发件人页面代码 <form id="form1" runat="server" method="post" action="CILandingPage.aspx"> <asp:TextBox name="txtUname" runat="server" Width="180px"></asp:TextBox> <asp:TextBox name="txtP

我正在尝试一个简单的HTTP post,以便在asp.net中将数据从一个表单发布到另一个表单。 发件人页面代码

 <form id="form1" runat="server" method="post" action="CILandingPage.aspx">
<asp:TextBox name="txtUname" runat="server" Width="180px"></asp:TextBox>
<asp:TextBox name="txtPassword" runat="server" TextMode="Password" Width="180px"></asp:TextBox>
 <asp:TextBox name="txtTransaction" runat="server" Width="180px"></asp:TextBox>
它引发NullReferenceException,因为Request.Form对象为空


我遗漏了什么?

由于您正在发布跨页信息,所以很可能收集项目(TXT密码)不存在。您可以尝试将每个控件的ClientIdMode设置为static,以便HTTP post中使用的id与您在目标页上的.Form集合中查找的id相匹配

查看本文了解有关跨页面发布的更多信息:


使用浏览器调试工具(F12)查看HTTP Post正文中传输的内容

设置要将ASP.NET Web表单页面发布到的页面的
PostBackUrl

删除
操作
添加到
按钮
中。改用名称使用属性值

默认为.aspx

<form id="form1" runat="server" method="post">
<div>       
    <asp:TextBox ID="TextBox1" name="txtUname" runat="server" Width="180px"></asp:TextBox>
    <asp:TextBox ID="TextBox2" name="txtPassword" runat="server" TextMode="Password" Width="180px"></asp:TextBox>
    <asp:TextBox ID="TextBox3" name="txtTransaction" runat="server" Width="180px"></asp:TextBox>
    <asp:Button ID="button" PostBackUrl="~/CILandingPage.aspx" runat="server" />           
</div>
</form>

您可以使用上一页参考,如下所示:

protected void Page_Load(object sender, EventArgs e)  
{  
// first check if we had a cross page postback  
    if ( (PreviousPage != null) && (PreviousPage.IsCrossPagePostBack))  
    {  
        Page previousPage = PreviousPage;
        TextBox UserName= (TextBox)previousPage.FindControl("txtUname");
        TextBox Password= (TextBox)previousPage.FindControl("txtPassword");
        // we can now use the values from TextBoxes and display them in two Label controls..
        lblUserName.Text = UserName.Text;
        blPassword.Text = Password.Text;
    }  
}  
页面加载中的此代码将被引用到上一个发布数据的页面,并帮助您在目标页面上获得相同的数据


希望这有帮助

尝试检查您的
HttpContext.Current.Request.Form
在asp.net 4.5中禁用自动友好URL
using System;

public partial class CILandingPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.Write(Request.Form["TextBox1"].ToString() +Environment.NewLine);
            Response.Write(Request.Form["TextBox2"].ToString() + Environment.NewLine);
            Response.Write(Request.Form["TextBox3"].ToString());            
        }
    }
}
protected void Page_Load(object sender, EventArgs e)  
{  
// first check if we had a cross page postback  
    if ( (PreviousPage != null) && (PreviousPage.IsCrossPagePostBack))  
    {  
        Page previousPage = PreviousPage;
        TextBox UserName= (TextBox)previousPage.FindControl("txtUname");
        TextBox Password= (TextBox)previousPage.FindControl("txtPassword");
        // we can now use the values from TextBoxes and display them in two Label controls..
        lblUserName.Text = UserName.Text;
        blPassword.Text = Password.Text;
    }  
}