using a global variable set by master page


D

Davids

I am not having any success, in my master.cs page I assign a variable to be
used within all other pages:

public partial class MP_master
{
public string MyString = "this string is global";
}

well accessing it from other pages brings a "CS0103: The name 'MyString'
does not exist in the current context
" error?
 
Ad

Advertisements

S

Scott Allen

Hi Davids:

The MyString field isn't really 'global' in the sense that you still
need an instance of MP_master to access the field. Perhaps you want to
mark MyString with the static keyword and associate the field with the
type? i.e: MP_master.MyString
 
Ad

Advertisements

D

Davids

found it...
what I forgot to do was to instantiate an inherited masterpage class:

MP_master masterpage = new MP_Master();


and then

masterpage.string = ...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top