【问题标题】:Access previous page controls value访问上一页控件值
【发布时间】:2014-05-21 08:58:08
【问题描述】:

我有一个问题,我想访问以前页面值的控件。我知道我可以使用 postbackurl 但我必须使用 OnClientClick 属性,因为我必须调用 javascript 方法并根据我的 url 更改的标准。下面的方法称为 OnClientClick 属性。此页面名称Calculator.aspx

        function redirectSellPage() {

        var type = getParameterByName('type');


        if (type == 'test') {
            window.location.href = "Change.aspx?PageType=a";
        } else if (a == null || a == "") {
            window.location.href = "Change.aspx?PageType=b";
        } else {
            window.location.href = "Change.aspx?PageType=c";
        }


    }

我想访问 Change.aspx 中的 Calculator.aspx 控件值。 我该怎么做。

【问题讨论】:

  • 为什么不将 Calculator.aspx 控件的值附加到 URL 中?
  • 您可以使用 dopostbackwithoptions 而不是设置 window.location.href=url。或者您可以将 form.action 设置为 url 并执行 form.submit。在这种情况下,您可以使用 Request.Form["name"] 访问上一页控件。

标签: c# javascript asp.net postback postbackurl


【解决方案1】:

在源页面中,在你的例子中是 Calculator.aspx,添加这个:

public String Value1
{
get
{
    return YourTextBoxId.Text;
}
}

在目标页面上,在你的例子中是 Change.aspx,添加一个指向源页面的 @PreviousPageType 页面指令。

<%@ PreviousPageType VirtualPath="~/Calculator.aspx" %>

现在在目标页面中使用 PreviousPage 属性来访问值。

String val = PreviousPage.Value1;

【讨论】:

    猜你喜欢
    • 2016-08-26
    • 2013-07-19
    • 2012-05-14
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多