How to access public member variable in the parent page class from a Web User Control

Discussion in '.NET' started by dliu, May 30, 2009.

  1. dliu

    dliu

    Joined:
    Mar 3, 2009
    Messages:
    2
    The title pretty much says my problem.

    I have a .aspx main page

    - index.aspx.cs

    public partial class IndexPageClass : System.Web.UI.Page
    {
    public string m_strCustomerName = "abc";
    .
    .
    .
    }

    - In index.aspx, I need to display it in a list.

    <%@ Register Src="signin.ascx" TagName="signin" TagPrefix="uc2" %>
    <li><b><a>Hi, <%=m_strCustomerName%></a></b></li>


    So in my signin.ascx user control, when the customer logs in, I will get the customer name and want to update it in main index.aspx page. But I haven't found an easy way to do it except to use session variable which is kinda strange to me. (It should work though)

    Casting doesn't work.
    IndexPageClass bp = (IndexPageClass)this.Page;
    Error I got:

    "Unable to cast object of type 'ASP.index_aspx' to type 'IndexPageClass'.
    Description: An unhandled exception occurred during the execution of the current web request. Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP.index_aspx' to type 'IndexPageClass'."

    I know 'ASP.index_aspx' is a class created by .Net:

    public class index_aspx : global::thebcguide.IndexPageClass, System.Web.IHttpHandler

    Is there any way I can cast or access my 'IndexPageClass' class? I am frustrated. Any serious help would be appreciated.
     
    dliu, May 30, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,376
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    584
    SpamProof
    Oct 21, 2003
  3. DaveLessnau
    Replies:
    3
    Views:
    429
    Howard
    May 16, 2005
  4. Jurek Dabrowski
    Replies:
    3
    Views:
    537
    Jurek Dabrowski
    Feb 18, 2007
  5. Peng Yu
    Replies:
    3
    Views:
    1,085
    Simon Forman
    Sep 21, 2009
Loading...

Share This Page