473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
Nov 19 '05 #1
2 3675
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

Nov 19 '05 #2
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" <Pa******@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Mantoulidis | last post by:
Seperate compilation (that's what it's called, right?) seems to be quite popular, so I decided to get some info about it, and (d'oh) use it... But it's whole structure seems weird to me... ...
18
by: Exits Funnel | last post by:
Hello, I'm a little confused about where I should include header files and was wondering whether there was some convention. Imagine I've written a class foo and put the definition in foo.h and...
12
by: blueblueblue2005 | last post by:
Hi, here is an example I copied from Deitel C++ book. but when I compile it, always get the above compilation error, no matter how I change the include order, please help. here is the files:...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
1
by: Lauchlan M | last post by:
Hi. I have an ASP.net project that works fine. I copied it to another project using the following steps: << (i) create a new VS.NET ASP.NET project.
5
by: Mikael S. H. | last post by:
Header file compilation I'm coding a small irc bot, and I've noticed that compilation takes very long when I add certain header files (compared to compilation time without). I've tried to find...
4
by: Madhur | last post by:
I have problems faced in adding definitions in the command header file. I have defined a header file which includes huge set of global constants and I am using them in all the C files. For...
1
by: jacek.dziedzic | last post by:
Hi! I have a program that #includes a header file of an external library. If the environment is set-up correctly, this file is found in the include path and everything works. Now, assume...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.