473,402 Members | 2,053 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,402 software developers and data experts.

Passing an Array into Viewstate

I'm developing a form that captures patient information. In the form, I
need the ability to add several insurance policies. The approach I have
decided to take is to load the separate insurance policies into a
multidimensional array. So:

// I create my array

string[,] arrInsurance = new string[5,15];

// During the AddButton_Click routine, I fill out my array with the current
data in the insurance form

arrInsurance[i,0] = "0" ;

arrInsurance[i,1] = "2" ;

arrInsurance[i,2] = strCompanyName ;

arrInsurance[i,3] = strStreetNbr ;

arrInsurance[i,4] = strStreetName ;

arrInsurance[i,5] = strCity ;

arrInsurance[i,6] = strState ;

arrInsurance[i,7] = strZip ;

arrInsurance[i,8] = strGroupNbr ;

arrInsurance[i,9] = strPolicyNbr ;

arrInsurance[i,10] = strClaimOrder ;

arrInsurance[i,11] = strPolicyType ;

arrInsurance[i,12] = strPolicyHolder ;

arrInsurance[i,13] = strSSN ;

arrInsurance[i,14] = strDOB ;

// But I need to save my array before I leave the AddButton_Click routine
into Viewstate, so I don't lose the data:

ViewState["ArrInsurance"] = arrInsurance. ;

This is about as far as I can get. The form lists the added insurance
policy, and allows the user to add another if they need to do so. The form
is reloaded and I lose my data. So I need to store the data in ViewState so
I can grab it back out of the array. The program bombs with some general
error, and I just can't figure this one out. Thank you in advance for
helping me with this.

While were at it, how do I get the array back from viewstate?
Nov 17 '05 #1
1 8469
it might be better to avoid viewstate storage.
Heres a simple example (session)

public class PolicyInput : System.Web.UI.Page {

void ShowPolicyList() {
ArrayList list = PolicyList;
if (list != null) {
foreach(Policy p in list) {
//show policy here
}
}
}

ArrayList PolicyList {
get {
ArrayList list = (ArrayList)Session["PolicyList"];
if (list == null) {
Session["PolicyList"] = new ArrayList();
}
return list;
}

private void btnAddPolicy_Click(object sender, System.EventArgs e) {
if (txtPolicyName.Text.Trim() != null) {
ArrayList list = PolicyList;
list.Add(new Policy(txtPolicyName.Text.Trim()));
//...
ShowPolicyList();
}
}

}

//Policy class
class Policy {

string name;

public Policy(string name) {
this.name = name;
}

public string Name {
get {
return name;
}
}

}

Hope this helps

Nov 17 '05 #2

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

Similar topics

11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
0
by: wASP | last post by:
I thought it was something relatively simple: ViewState = SomeObj; Then: SomeObj = ViewState; So, in my own code, I have this on the initial load:
1
by: bob | last post by:
I am a newbie. How do I add an array to a viewstate, then retreive the individual elements? Right now, I made an array with random numbers and when I go to access an element from different...
2
by: Gopal Krish | last post by:
Folks, How to add an array to a ViewState in C#? I'm doing the following and .net does not likes it. ViewState = HeadingArray; where HeadingArray is a two dimensional array.
4
by: Robert P. | last post by:
I can easily store a one-dimensional array in viewstate ( see Test1 ) If I try storing a multi-dimensional array in the viewstate it's crapping out on me when it goes to serialize the array (not...
5
by: danc | last post by:
I keep getting this error. I have scoured the web and could not find any applicable information. It seems to have really started since I upgraded to the 1.1 framework. Any help is appreciated. ...
2
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Hey guys, Can anyone tell me how I can do THIS (see code below) but in a STRING ARRAY instead? I really appreciate any help. I'm using C# in VS2005. public int intTotal { get {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.