Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing an Array in viewstate

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US
From what I've read, an array can be stored in viewstate but from what I've tried ... I've been very unsuccessful in making this happen. How does one accomplish this?

These are some important snippets of my code:

Code:
protected String[,] employeeArray = new String[100, 3];

private void Page_Load(object sender, System.EventArgs e)
{
 if ( !Page.IsPostBack )
 {
	retrieve_employees();
	(string[,])ViewState["employees"] = employeeArray;
	setCounterValues();
 }
}

public void btnNext_Click(object sender, ImageClickEventArgs e)
{
	employeeArray = (string[,])ViewState["employees"];
	setCounterValues();
}

When the page is loaded the array is populated. When the button is clicked I want to reuse the list without having to repopulate it.

Any ideas?

- VBRookie
 
I am not sure of the C#? syntax you are using. However, ViewState has a Item and an Add Property that you should use.

ViewState.Add("Employee", employeeArray)
employeeArray = viewstate.Item("employee")


This is done in VB but it works perfectly for me. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Zarcom,

The first line works but the second is giving me trouble. I made the necessary changes for C# but its still not working. I'm having a hard time getting the values out of viewstate.
 
What error/event are you getting when you use the second line? That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top