0

Using C# and ASP.net, I have an array of doubles that is filled up with information from a file. When it is finally full it shows to the user how many fields are full in a label.

this code is to fill one array from a file, this code is inside a button.

double[] arrayX; //imagine this is a global variable.

string line;
int j = 0;

Stream data = FileUpload1.PostedFile.Inputstream;
StreamReader sr = new StreamReader(data);

line = sr.ReadLine();
while (line != null)
{
  arrayX[j] = Convert.ToDouble(line);
  j++;
  line = sr.ReadLine();
}
label1.Text = j.ToString();

Now in the web browser it shows the number of elements like this: No. of elements: __10___

if the user agrees with this number, he clicks the second button which will have to use the array that was filled for some other operation but in my webbrowser it says that the array is empty even if i have declare as a global variable.

So my question is, how can i read my array data from the second button?

1 Answer 1

1

you need to save the array in a view-data or session and then access the array from session or viewstate

in your original method

ViewState["mtarray"] = arrayX;

and in your button method

 arrayX=ViewState["mtarray"] as double[];

http://msdn.microsoft.com/en-us/library/ms972976.aspx

Sign up to request clarification or add additional context in comments.

5 Comments

+0, You haven't explained what ViewData or a session is, nor have you explained to the OP why he is experiencing the behavior that he is. your answer likely won't help the OP very much
@Sam I am I did not finished answering my question I was just saving the what I put
+1 I think this answer is a sufficient starting point. Google can do the rest.
Ah yes, the "get in" first ploy.
i try to save it as a session before then i recive an error cant remenber what it was, since firts i am tring to send one array and in another program it has to send an array of array i am goig to try the viewState to see if it works mean while thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.