473,748 Members | 7,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
multidimensiona l 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["ArrInsuran ce"] = 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 8509
it might be better to avoid viewstate storage.
Heres a simple example (session)

public class PolicyInput : System.Web.UI.P age {

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

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

private void btnAddPolicy_Cl ick(object sender, System.EventArg s e) {
if (txtPolicyName. Text.Trim() != null) {
ArrayList list = PolicyList;
list.Add(new Policy(txtPolic yName.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
2175
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 datagrid. I am using the viewstate object to store the Arraylist items on the page on postback. My PROBLEM is that I need to redirect the user to a new aspx page and on this new page i need to be able to access the items in my arraylist. Is this...
58
10170
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 code... TCHAR myArray; DoStuff(myArray);
0
1306
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
2122
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 buttons, if I access the same element, it looks like it is putting new random numbers in the array. I just want to establish an array only once with random numbers, and being able to get the same answers when ever I access the elements of the array.
2
4025
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
4519
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 when I make the assignment). Interestingly, I get a very different error depending on the type of array ( string or decimal ). I'm not doing anything fancy, just a regular old aspx page with a single
5
11320
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. Using: *ASP.NET 1.1 *Single machine (no clusters) *Simple postbacks (no postbacks to different pages) *Using only Response.Redirect() when applicable *The page works fine. The error appears at random occasions.
2
10039
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
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8237
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.