【问题标题】:how I can retrive the value of variable in aspx on ascx page behind如何在 ascx 页面后面的 aspx 中检索变量的值
【发布时间】:2016-12-02 20:00:48
【问题描述】:

我后面有aspx code

public partial class allahabad : System.Web.UI.Page
{
    int insid = 123;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

现在我的 ascx 代码在上面的 aspx 页面中注册,在 ascx 页面中我有一个按钮控件,我想在哪个点击事件上将 int insid 的值发送到目标页面,我不想使用 session。任何人都可以帮助我怎么做。

ascx 页面代码

public partial class GFTindia_customcontrol_mycustomcontrol : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/GFTindia/targetpage.aspx?id=" + insid);
    }
}

【问题讨论】:

  • 您知道页面类实例变量不会在回发后持续存在,因此您在 Page_Load 中设置的任何内容都会在点击事件运行时被设置,对吧?

标签: asp.net


【解决方案1】:

给你的用户控件一个公共属性。

public partial class GFTindia_customcontrol_mycustomcontrol : System.Web.UI.UserControl
{
    public int insid { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Redirect("~/GFTindia/targetpage.aspx?id=" + insid, false);
    }
}

然后您可以从父页面设置或获取值。

WebUserControl1.insid = insid;

WebUserControl1 是控件的 ID。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 2012-03-18
    • 1970-01-01
    相关资源
    最近更新 更多