473,569 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you store a stoopid array in the stoopid ViewState?


I thought it was something relatively simple:

ViewState["SomeObj"] = SomeObj;

Then:

SomeObj = ViewState["SomeObj"];
So, in my own code, I have this on the initial load:
UInt32[] int_array = new UInt32[11];

... and:

ViewState["int_array"] = int_array;

THEN, on postback, I have this:

UInt32[] int_array = (UInt32[]) ViewState["int_array"];

... and:

for (UInt32 nn = 0; nn < 11; nn++)
int_array[nn] += 1;

On the FOR loop, an exception gets thrown:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Server Error in '/Webfolder01' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object reference
not set to an instance of an object.

Source Error:
Line 84: for (UInt32 nn = 0; nn < 11; nn++)
Line 85: zxc[nn] += 1;
Line 86:
Line 87: for (UInt32 nn = 0; nn < 11; nn++)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Does anyone know what I need to do to store a stoopid array
in the stoopid ViewState?

It would improve my mental health to know this.

BTW: Is there any way to create an immediate array (from the program stack) in C#?

It seems like the only way to create an array is to dynamically allocate
the space for it and assign the pointer to a reference type.

IOW, In C++, it's sort of like this:

int (*int_array)[] = farmalloc (11);
... instead of like this:

int int_array[11];

I don't see anything in any docs on C# that will let you do that.

Did I miss something?

My Page_Init handler is as follows:
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

public void Page_Init (object sender, EventArgs e)
{
int ndx = 3;

if (!Page.IsPostBa ck)
{ string msg1;
UInt32[] int_array = new UInt32[11];

msg1 = " first load: |";
for (UInt32 nn = 0; nn < 11; nn++)
int_array[nn] = 100 - nn;

for (UInt32 nn = 0; nn < 11; nn++)
msg1 = msg1 + int_array[nn].ToString() + "|";

msg1 = msg1 + "<br>";

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( msg1) );

ViewState["int_array"] = int_array;
}
else
{ string msg1 = " On postback: |";

UInt32[] int_array = (UInt32[]) ViewState["int_array"];

for (UInt32 nn = 0; nn < 11; nn++)
int_array[nn] += 1;

for (UInt32 nn = 0; nn < 11; nn++)
msg1 = msg1 + int_array[nn].ToString() + "|";

msg1 = msg1 + "<br>";

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( msg1) );
}

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>||| added 1 on init |||<br><br>") );

xPage_Load (sender, e);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

THANKS!!!

- wASP
Nov 17 '05 #1
0 1300

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

Similar topics

11
2513
by: Colin Steadman | last post by:
Hope this makes sense! I'm building an ASP page which allows uses to add items to an invoice via a form, ie: Item No Part No Order No Quanity Units Price VAT ------- ------- -------- ------- ----- ----- --- .... ... ... ... ... ... ... <Add item>...
3
8571
by: jacob nikom | last post by:
Hi, I would like to be able to store numerical array in MySQL. I am really looking for the solution to store it in the one field only. For example, I have a matrix, which I want to store in the table, but I don't want to create one column per matrix element - too many columns or matrix size could change easily. Should I convert all...
1
8494
by: John Miller | last post by:
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;
1
2112
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...
2
4018
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
4506
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...
0
4569
by: rajamohammed | last post by:
Can anyone please help me how to store byte array in SQL database? Please give some sample code. Thanks in advance.
5
4658
rahulephp
by: rahulephp | last post by:
Hi there, can you please help me? i have data in array and i want to insert it in a single table. structure of table and array to be store is shown below: Please let me know how to store this array in database? Database Structure:
3
10552
by: Arjun Sarankulu | last post by:
I want to read numbers from XML file Suppose xml file contain <number>1</number> <number>10</number> <number>20</number> <number>30</number> <number>69</number> The above mention numbers in XML file, i want to store in array. Can any one help me for the same
0
7701
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...
0
7615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
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...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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...
0
3653
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...
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.