开发者

Call Public Property Declared in a ASPX Page from a Different ASPX Page

How can I call a public property declared on a ASPX page from a different ASPX Page? Is that possible? It is a website project. How can I get/call this property from a different aspx page? I have attempted this from the other page, but it is not recognizing the partial class: private Test_Default _test; It does not reco开发者_运维问答gnize the "Test_Default"

I.E.

public partial class Test_Default : System.Web.UI.Page  
{  
    private string myAge = string.empty;  
    public string Name  
    {  
        get   
        {  
        return myName;   
        }  
        set   
        {  
        myName = value;   
        }  
}


If you need a piece of shared code, create a class for it in the APP_CODE folder.

See MSDN documentation here and here.


I would create a separate class exposing the property you are wanting to work with, and store the value in Session :

public class MyClass
{
    public static string MyName
    {
        get
        {
            if (Session["MY_NAME"] != null)
            {
                return Session["MY_NAME"].ToString();
            }
            return String.Empty;
        }
        set { Session["MY_NAME"] = value; }
    }
}

You should be able to call that from either Page. If it's a complex object, then change the type from string to your object.

Hope that helps!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜