我怎样才能在ascx页面后面的aspx中检索变量的值

时间:2016-12-02 20:00:48

标签: asp.net

我背后有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的值发送到目标页面的click事件,我不想使用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);
    }
}

1 个答案:

答案 0 :(得分:0)

为您的用户控件提供公共属性。

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。