【问题标题】:Ajaxpro methods get global page variable to be reinitialized?Ajaxpro 方法获取要重新初始化的全局页面变量?
【发布时间】:2012-08-03 14:31:00
【问题描述】:

我对 ajaxpro 方法有疑问。在 .cs 文件中,我为我的页面定义了一些全局变量,例如:

public partial class Admin : System.Web.UI.Page
{
    public int localidMember = 9;
    protected void Page_Load(object sender, EventArgs e)
    {

        AjaxPro.Utility.RegisterTypeForAjax(typeof(Admin));


        if (HttpContext.Current.Session["HomeOwn_ID"] != null)
        {
            localidMember = Convert.ToInt32(HttpContext.Current.Session["HomeOwn_ID"].ToString());

        }

    }


    [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
    public string LoadInbox()
    {
        // I need to use the variable localidMember and expected that it will have the value that I have set to pageload.., but it didnt. The variable is reinitialized to 9... Anyone have any ideas what's going on... Thanks so much ! 
    }

}

【问题讨论】:

    标签: asp.net global-variables pagemethods ajaxpro


    【解决方案1】:

    我认为你做不到;因为,在 AjaxPro 中,您无法处理控件属性。

    【讨论】:

      【解决方案2】:

      AjaxMethod 将有自己的上下文。因此,localidMember 将无法在其中访问。您可以考虑将其作为参数传递。

      【讨论】:

        猜你喜欢
        • 2015-03-29
        • 2022-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多