【问题标题】:Response.Redirect is not passing the value to another webformResponse.Redirect 没有将值传递给另一个网络表单
【发布时间】:2018-11-22 02:24:01
【问题描述】:

我正在尝试将ClientGroupRegistration.aspx 中的文本框值传递给BorrowerRegistration.aspx 中的标签。我正在使用 QueryString 方法,但是,以下代码对我不起作用。没有值被传递给relationshipNameLabel.Text

来自 ClientGroupRegistration.aspx

protected void nextPageButton_Click(object sender, EventArgs e) 
{
    ClientGroup client = new ClientGroup(this.addRelationshipName, this.addRelationshipComments);
    Response.Redirect("~/WebPages/BorrowerRegistration.aspx?Parameter=" + client.ClientName().ToString(), false); //ClientName() method returns a client name
}

BorrowerRegistration.aspx

protected void Page_Load(object sender, EventArgs e)
{           
    relationshipNameLabel.Text = Request.QueryString["Parameter"];                  
}

【问题讨论】:

  • 请在 Chrome 中加载第一页。加载开发者工具。转到网络选项卡。勾选Preserve log。单击下一页按钮。请向我们显示下一个请求的请求和响应标头。
  • 一个很可能的原因是 client.ClientName() 返回一个空字符串。所以价值被传递了。它只是空的。你可以在重定向行上设置断点,看看属性的值是什么。

标签: c# asp.net webforms query-string


【解决方案1】:

当您重定向到 BorrowerRegistration 页面时,您是否检查了 URL? 如果它没有 QueryString 值,那么您的客户端方法将返回 NULL 值。 URL 将类似于:

BorrowerRegistration.aspx?Parameter=

【讨论】:

  • 我什至试过这个 Response.Redirect("BorrowerRegistration.aspx?Parameter=JoJo");仍然没有值被传递给reationshipNameLabel.Text。
【解决方案2】:

确保 URL 中有你的参数,如果有,那么你必须在 BorrowerRegistration.aspx.cs

中执行类似的操作
protected void Page_Load(object sender, EventArgs e)
{           
    if (Request.QueryString["Parameter"] != null)
        relationshipNameLabel.Text = Request.QueryString["Parameter"].ToString();                  
}

【讨论】:

    猜你喜欢
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 2011-11-05
    相关资源
    最近更新 更多