Syntax Challenged

J

Jim McGivney

I find myself Syntax Challenged.
An array resides on a MasterPage.
I want to use the values of the array on an aspx page which is a content
page of the MasterPage.
I can not find the syntax that works.

For a single value (non-array) the following will work.

On the MasterPage:
public String CompanyName
{
get { return (String) ViewState["companyName"]; }
set { ViewState["companyName"] = value; }
}
void Page_Init(Object sender, EventArgs e)
{
this.CompanyName = "JimBo";
}On the ContentPage:<%@ MasterType virtualpath="~/Master1.master" %>void
Page_Load(Object sender, EventArgs e)
{
Label1.Text = Master.CompanyName;
}I need the equivalent code for a array. Code examples would be
appreciated.Thanks,Jim
 
R

Ray Booysen

public String[] MyArray
{
get { return (String[]) ViewState["MyArray"]; }
set { ViewState["MyArray"] = value; }
}
 
J

Jim McGivney

Ray:
This generates an error:
public String[] MyArray
{
get { return (String[])ViewState["MyArray"]; }
set { ViewState["MyArray"] = value; }
}

protected void Button1_Click(object sender, EventArgs e)
{
MyArray[0] = "Zero";
Label1.Text = MyArray[0].ToString();
// Generates error: Object reference not set to an instance of an object.
}





Ray Booysen said:
public String[] MyArray
{
get { return (String[]) ViewState["MyArray"]; }
set { ViewState["MyArray"] = value; }
}




Jim said:
I find myself Syntax Challenged.
An array resides on a MasterPage.
I want to use the values of the array on an aspx page which is a content
page of the MasterPage.
I can not find the syntax that works.

For a single value (non-array) the following will work.

On the MasterPage:
public String CompanyName
{
get { return (String) ViewState["companyName"]; }
set { ViewState["companyName"] = value; }
}
void Page_Init(Object sender, EventArgs e)
{
this.CompanyName = "JimBo";
}On the ContentPage:<%@ MasterType virtualpath="~/Master1.master" %>void
Page_Load(Object sender, EventArgs e)
{
Label1.Text = Master.CompanyName;
}I need the equivalent code for a array. Code examples would be
appreciated.Thanks,Jim
 
R

Ray Booysen

I was just showing you how to create the property.

Where are you created the array to set it to the property.

Using:
String[] _a = new String[1] {"Hello"};

You can create the array and then set it to the property:

MyArray = _a;

Then:

MyArray[0] = "Zero" will work.



Jim said:
Ray:
This generates an error:
public String[] MyArray
{
get { return (String[])ViewState["MyArray"]; }
set { ViewState["MyArray"] = value; }
}

protected void Button1_Click(object sender, EventArgs e)
{
MyArray[0] = "Zero";
Label1.Text = MyArray[0].ToString();
// Generates error: Object reference not set to an instance of an object.
}





Ray Booysen said:
public String[] MyArray
{
get { return (String[]) ViewState["MyArray"]; }
set { ViewState["MyArray"] = value; }
}




Jim said:
I find myself Syntax Challenged.
An array resides on a MasterPage.
I want to use the values of the array on an aspx page which is a content
page of the MasterPage.
I can not find the syntax that works.

For a single value (non-array) the following will work.

On the MasterPage:
public String CompanyName
{
get { return (String) ViewState["companyName"]; }
set { ViewState["companyName"] = value; }
}
void Page_Init(Object sender, EventArgs e)
{
this.CompanyName = "JimBo";
}On the ContentPage:<%@ MasterType virtualpath="~/Master1.master" %>void
Page_Load(Object sender, EventArgs e)
{
Label1.Text = Master.CompanyName;
}I need the equivalent code for a array. Code examples would be
appreciated.Thanks,Jim
 
J

Jim McGivney

Thanks Ray, it worked.
Jim


Ray Booysen said:
I was just showing you how to create the property.

Where are you created the array to set it to the property.

Using:
String[] _a = new String[1] {"Hello"};

You can create the array and then set it to the property:

MyArray = _a;

Then:

MyArray[0] = "Zero" will work.



Jim said:
Ray:
This generates an error:
public String[] MyArray
{
get { return (String[])ViewState["MyArray"]; }
set { ViewState["MyArray"] = value; }
}

protected void Button1_Click(object sender, EventArgs e)
{
MyArray[0] = "Zero";
Label1.Text = MyArray[0].ToString();
// Generates error: Object reference not set to an instance of an object.
}





Ray Booysen said:
public String[] MyArray
{
get { return (String[]) ViewState["MyArray"]; }
set { ViewState["MyArray"] = value; }
}




Jim McGivney wrote:
I find myself Syntax Challenged.
An array resides on a MasterPage.
I want to use the values of the array on an aspx page which is a
content page of the MasterPage.
I can not find the syntax that works.

For a single value (non-array) the following will work.

On the MasterPage:
public String CompanyName
{
get { return (String) ViewState["companyName"]; }
set { ViewState["companyName"] = value; }
}
void Page_Init(Object sender, EventArgs e)
{
this.CompanyName = "JimBo";
}On the ContentPage:<%@ MasterType virtualpath="~/Master1.master"
%>void Page_Load(Object sender, EventArgs e)
{
Label1.Text = Master.CompanyName;
}I need the equivalent code for a array. Code examples would be
appreciated.Thanks,Jim
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,153
Latest member
NamKaufman
Top