Asp.net Header file scenario please ... (compilation err)

Discussion in 'ASP .Net' started by Annie, Sep 7, 2005.

  1. Annie

    Annie Guest

    hello guys,

    I have a header file in the form of user control (.ascx) that all my pages
    inherit from it. I have a textbox that i need to access it
    from all the pages actually i show there user details there and needs to
    update it. So i set this textbox as Public and Static. The
    code compiles fine and the textbox is accessable to all pages however i have
    the following compilation errr:

    Compiler Error Message: CS0176: Static member 'MobileShop.Header.txtClient'
    cannot be accessed with an instance reference; qualify it with a type name
    instead

    Source Error:


    Line 1: <%@ Control Language="c#" AutoEventWireup="false"
    Codebehind="Header.ascx.cs" Inherits="MobileShop.Header"
    targetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    Line 2: <P style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PAGE-BREAK-BEFORE:
    auto; PADDING-BOTTOM: 0px; MARGIN: 0px; PAGE-BREAK-AFTER: auto; CLIP:
    rect(0px auto auto 0px); PADDING-TOP: 0px; POSITION: static; TEXT-ALIGN:
    left"
    Line 3: align="left">

    Source File: http://localhost/MobileShop/Header.ascx Line: 1


    I don't know why this error please help

    TIA
    Annie, Sep 7, 2005
    #1
    1. Advertising

  2. G'day Annie.

    Presumably you are using c#...

    You are probably doing something like this:

    this.myheader.TheTextBox.Text = "hello world" ;

    Try changing the "this.myheader" - i.e. referencing the TextBox via the
    instance - to something like:
    MyProject.headerControlClass.TextBox.Text = "hello world" ;
    i.e. reference it via the Class name, rather than the instance name...


    Hth,

    Cheers,

    Paul

    "Annie" wrote:

    > hello guys,
    >
    > I have a header file in the form of user control (.ascx) that all my pages
    > inherit from it. I have a textbox that i need to access it
    > from all the pages actually i show there user details there and needs to
    > update it. So i set this textbox as Public and Static. The
    > code compiles fine and the textbox is accessable to all pages however i have
    > the following compilation errr:
    >
    > Compiler Error Message: CS0176: Static member 'MobileShop.Header.txtClient'
    > cannot be accessed with an instance reference; qualify it with a type name
    > instead
    >
    > Source Error:
    >
    >
    > Line 1: <%@ Control Language="c#" AutoEventWireup="false"
    > Codebehind="Header.ascx.cs" Inherits="MobileShop.Header"
    > targetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    > Line 2: <P style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PAGE-BREAK-BEFORE:
    > auto; PADDING-BOTTOM: 0px; MARGIN: 0px; PAGE-BREAK-AFTER: auto; CLIP:
    > rect(0px auto auto 0px); PADDING-TOP: 0px; POSITION: static; TEXT-ALIGN:
    > left"
    > Line 3: align="left">
    >
    > Source File: http://localhost/MobileShop/Header.ascx Line: 1
    >
    >
    > I don't know why this error please help
    >
    > TIA
    >
    >
    >
    =?Utf-8?B?UGF1bCBEIE1jTQ==?=, Sep 7, 2005
    #2
    1. Advertising

  3. Annie

    Annie Guest

    Hi Paul,

    Thanks for your reply. It is correct i am using c#.

    The error message is same as it was before. I am doing it as you were
    suggesting but I think it doesn't like the keyword Static???
    What are the other ways to access this textbox in the header file??? Or
    maybe it should be done after PageLoad event? at the
    moment I am keeping the code in the page load event of the page as:

    public class SpecialOffers : System.Web.UI.Page, IPageToIncludeHeaderFooter
    //this is the interface for Header and Footer that i implement

    {

    protected System.Web.UI.WebControls.Image imgPromotion;

    protected System.Web.UI.WebControls.Label lblPromotion;

    protected System.Web.UI.WebControls.HyperLink hlPromotion;

    protected System.Web.UI.WebControls.TextBox txtHidden;


    private void Page_Load(object sender, System.EventArgs e)

    {

    Response.Write(GlobalObject.FirstName);

    txtHidden.Text= GlobalObject.FirstName;

    Response.Write(GlobalObject.LastName);

    MobileShop.Header.txtUserName.Text="hello";

    }


    Compiler Error Message: CS0176: Static member
    'MobileShop.Header.txtUserName' cannot be accessed with an instance
    reference; qualify it with a type name instead

    Source Error:


    Line 1: <%@ Control Language="c#" AutoEventWireup="false"
    Codebehind="Header.ascx.cs" Inherits="MobileShop.Header"
    targetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    Line 2: <P style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PAGE-BREAK-BEFORE:
    auto; PADDING-BOTTOM: 0px; MARGIN: 0px; PAGE-BREAK-AFTER: auto; CLIP:
    rect(0px auto auto 0px); PADDING-TOP: 0px; POSITION: static; TEXT-ALIGN:
    left"
    Line 3: align="left">

    "Paul D McM" <> wrote in message
    news:...
    > G'day Annie.
    >
    > Presumably you are using c#...
    >
    > You are probably doing something like this:
    >
    > this.myheader.TheTextBox.Text = "hello world" ;
    >
    > Try changing the "this.myheader" - i.e. referencing the TextBox via the
    > instance - to something like:
    > MyProject.headerControlClass.TextBox.Text = "hello world" ;
    > i.e. reference it via the Class name, rather than the instance name...
    >
    >
    > Hth,
    >
    > Cheers,
    >
    > Paul
    >
    > "Annie" wrote:
    >
    >> hello guys,
    >>
    >> I have a header file in the form of user control (.ascx) that all my
    >> pages
    >> inherit from it. I have a textbox that i need to access it
    >> from all the pages actually i show there user details there and needs to
    >> update it. So i set this textbox as Public and Static. The
    >> code compiles fine and the textbox is accessable to all pages however i
    >> have
    >> the following compilation errr:
    >>
    >> Compiler Error Message: CS0176: Static member
    >> 'MobileShop.Header.txtClient'
    >> cannot be accessed with an instance reference; qualify it with a type
    >> name
    >> instead
    >>
    >> Source Error:
    >>
    >>
    >> Line 1: <%@ Control Language="c#" AutoEventWireup="false"
    >> Codebehind="Header.ascx.cs" Inherits="MobileShop.Header"
    >> targetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    >> Line 2: <P style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px;
    >> PAGE-BREAK-BEFORE:
    >> auto; PADDING-BOTTOM: 0px; MARGIN: 0px; PAGE-BREAK-AFTER: auto; CLIP:
    >> rect(0px auto auto 0px); PADDING-TOP: 0px; POSITION: static; TEXT-ALIGN:
    >> left"
    >> Line 3: align="left">
    >>
    >> Source File: http://localhost/MobileShop/Header.ascx Line: 1
    >>
    >>
    >> I don't know why this error please help
    >>
    >> TIA
    >>
    >>
    >>
    Annie, Sep 8, 2005
    #3
    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.

Share This Page