在一个ASP.NET code公共属性后面应该页面加载的坚持? [英] Are public properties in an ASP.NET code behind supposed to persist between page loads?

查看:136
本文介绍了在一个ASP.NET code公共属性后面应该页面加载的坚持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图捕捉在ASP.NET页面的Page_Load事件中HTTP_REFERER和回发之间持续存在,直到后来我才需要它。我试图做到这一点的方法是行不通的:

I am trying to capture the HTTP_REFERER upon page_load event of an ASP.NET page, and persist it between postbacks until I need it later. The way I trying to do this isn't working:

public partial class About : System.Web.UI.Page
{
    public string ReferringPage { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ReferringPage = 
              Request.ServerVariables["HTTP_REFERER"];
        }
    }

    protected void ImageButton1_Click(
         object sender, ImageClickEventArgs e)
    {
        Response.Redirect(ReferringPage);
    }
}

我已经验证了其提交页面的网址进入的财产,但是当我点击图像按钮,ReferringPage为空!我原以为该属性的值存储在ViewState中,所以,这将是可根据回传,但这种结果并非如此。还是我只是做错了?

I've verified that the referring page's url goes into the property, but when I click the image button, ReferringPage is null! I had thought that the property's value was being stored in the ViewState, so that it would be available upon postback, but this turns out not to be the case. Or am I simply doing it wrong?

推荐答案

每个请求创建页面类的新实例,所以没,没什么是为了持续。

Every request creates a new instance of the page class, so no, nothing is meant to persist.

这篇关于在一个ASP.NET code公共属性后面应该页面加载的坚持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆