W
wASP
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.NullReferenceException: 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.IsPostBack)
{ 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_Placeholder.Controls.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_Placeholder.Controls.Add
( new LiteralControl(msg1) );
}
Dyn_Control_Placeholder.Controls.Add
( new LiteralControl("<br>||| added 1 on init |||<br><br>") );
xPage_Load (sender, e);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
THANKS!!!
- wASP
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.NullReferenceException: 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.IsPostBack)
{ 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_Placeholder.Controls.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_Placeholder.Controls.Add
( new LiteralControl(msg1) );
}
Dyn_Control_Placeholder.Controls.Add
( new LiteralControl("<br>||| added 1 on init |||<br><br>") );
xPage_Load (sender, e);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
THANKS!!!
- wASP