how to make a button static?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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?
 
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
 
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
 
Don't make it static.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
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)



| 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?
|
 
Back
Top