473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to make a button static?

hello i'm doing this

protected static System.Web.UI.WebControls.Button btnExcel;

hoping that it would remain shared but when i run the application i get this
error

Compiler Error Message: CS0176: Static member 'NPI.Search.btnExcel' cannot
be accessed with an instance reference; qualify it with a type name instead

any other how i can over come this problem?

Nov 19 '05 #1
5 2165
On Mon, 31 Jan 2005 19:43:02 -0800, =?Utf-8?B?QXNoYQ==?=
<As**@discussions.microsoft.com> wrote:
hello i'm doing this

protected static System.Web.UI.WebControls.Button btnExcel;

hoping that it would remain shared but when i run the application i get
this
error

Compiler Error Message: CS0176: Static member 'NPI.Search.btnExcel'
cannot
be accessed with an instance reference; qualify it with a type name
instead

any other how i can over come this problem?


If you look in the InitializeComponent method you'll notice it is pry
being accessed by the auto-generated code like this:

btnExcel.Text = "Excel";

since it's really an object (instance of a class). I'm not sure why
you're trying to do this, but if you changed the 'protected static'
portion to just 'public' is that good enough?

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2
I don't think it makes much sence. Web controls always live on pages.
Therefore you have to have a page instance reference to acces them. When you
write btnExcel it actually means this.btnExcel, where "this" is a reference
to the page.

Eliyahu

"Asha" <As**@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
hello i'm doing this

protected static System.Web.UI.WebControls.Button btnExcel;

hoping that it would remain shared but when i run the application i get this error

Compiler Error Message: CS0176: Static member 'NPI.Search.btnExcel' cannot
be accessed with an instance reference; qualify it with a type name instead
any other how i can over come this problem?

Nov 19 '05 #3
Won't work anyway IMO. The page just lives the time of the HTTP request. Why
would a button on this page live longer ?

You may want to tell us what you are trying to do...

Patrice

--

"Asha" <As**@discussions.microsoft.com> a écrit dans le message de
news:3B**********************************@microsof t.com...
hello i'm doing this

protected static System.Web.UI.WebControls.Button btnExcel;

hoping that it would remain shared but when i run the application i get this error

Compiler Error Message: CS0176: Static member 'NPI.Search.btnExcel' cannot
be accessed with an instance reference; qualify it with a type name instead
any other how i can over come this problem?

Nov 19 '05 #4
Don't make it static.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Asha" <As**@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
hello i'm doing this

protected static System.Web.UI.WebControls.Button btnExcel;

hoping that it would remain shared but when i run the application i get
this
error

Compiler Error Message: CS0176: Static member 'NPI.Search.btnExcel' cannot
be accessed with an instance reference; qualify it with a type name
instead

any other how i can over come this problem?

Nov 19 '05 #5
while it makes no sense to make the button static (and would prevent two
copies of the page running at the same time correctly), just replace all
references to 'btnExcel' with 'NPI.Search.btnExcel'.

'btnExcel' is a shortcut for 'this.btnExcel'. because 'btnExcel' is a
static, the default reference doesn't work.
-- bruce (sqlwork.com)

"Asha" <As**@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
| hello i'm doing this
|
| protected static System.Web.UI.WebControls.Button btnExcel;
|
| hoping that it would remain shared but when i run the application i get
this
| error
|
| Compiler Error Message: CS0176: Static member 'NPI.Search.btnExcel' cannot
| be accessed with an instance reference; qualify it with a type name
instead
|
| any other how i can over come this problem?
|
Nov 19 '05 #6

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

Similar topics

9
by: Ray Muforosky | last post by:
Hello, Is there a way to render a text or button tag without a sunken or raised surface respectively. Ray
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
6
by: divya | last post by:
I have a page name edit.asp which should expire immediately .The user cannot open this page directly he has to provide a password for entering this page.thus when the user enters edit.asp , it has...
2
by: Danny | last post by:
Hi I want to be able from my csharp button to start an application ( which I can do) and then somehow send a message to the win32 application that says "press the button" The win32...
0
by: jeff.sharkfinn | last post by:
I'm trying to create a pointer to a class in form1.h button1 event handler. It should be simple... but no. This example is as simple as I can make: Form1.h (produced with the designer containing...
18
by: bning | last post by:
Hmm this forum really doesn't give you long enough to type in your question before logging you out.. well here goes my second attempt: I'm trying to teach myself javascript with dom scripting and...
3
by: shimajavar | last post by:
Hi all I have the following code: a line is growing up by clicking on "up" button, it has another button"start" which I want it to stop the process of growing the line...How can I make a button to...
7
by: ITAutobot25 | last post by:
My delete button is not working in my GUI and my due date is today before midnight. Can anyone show me how to correct this error? My assignment statement is below as well as 5 classes. InventoryGUI...
2
by: chrisp | last post by:
I have an ASP.NET 2 page with a button that causes a credit card transaction to be authorised. The authorisation procedure may take a few seconds and so I want to prevent the user from clicking the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.