Solved

How to pass arraylist between updatepanels

Posted on 2010-11-25
11
365 Views
Last Modified: 2012-05-10
Hi,

I have a gridview that has some rows in a UpdatePanel, there is also a button that proceeds into another updatepanel. I add the gridview rows in an arraylist in the button_click event. How can I pass this arraylist to another function?
protected void Button_Click(object sender, EventArgs e)

        {

            

            string number;



            foreach (GridViewRow row in GridViewRCC.Rows)

            {

                //GridViewRCC.AllowPaging = false;

                number = GridViewRCC.DataKeys[row.RowIndex].Value.ToString();



                Recipients.Add(number);

            }

            updatePnl.Visible = true;

            UpdatePanel1.Visible = false;

            UpdatePanelSearch.Visible = false;

        }





 public void XXXX()

 {

//here I wan't to get the recipients arraylist....

}

Open in new window

0
Comment
Question by:mattegol
  • 6
  • 5
11 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34211631
You don't appear to declare "Recipients" in your click event, which suggests yuo have it defined at the page level somewhere. In which case you should simply be able to access directly, just as you do from the Click event handler.
0
 

Author Comment

by:mattegol
ID: 34211665
I have declared it: ArrayList Recipients = new ArrayList(); above Page_Load

I have used a session to make it work, but I dont know if thats the best way to go..?

first
Session["Recipients"] = (object)Recipients;

Then
ArrayList arr1 = new ArrayList();
                arr1 = (ArrayList)Session["Recipients"];
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34211671
If you need to hold on to that list between page requests then storing it in the session is a perfectly valid option.
0
 

Author Comment

by:mattegol
ID: 34211752
Ok, I'll go for the session then. Should I end the session somehow? because there will be a lot of sessions when hundreds of users are using this.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34211788
The sessions will end by themselves after a period of inactivity, 20 minutes by default.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mattegol
ID: 34211873
Yes I know but won't the hundreds of sessions effect the performance of the page?
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 34211893
It depends how much data you are planning to hold in the session. It won't affect the page itself, but it will affect the amount of memory being used on the server (if you're using InProcess state rather than a StateServer or SQL solution)

Do you need access to your arraylist across page requests? Can you safely clear it out again after your call to XXX()?
0
 

Author Comment

by:mattegol
ID: 34211920
I think it will be safe to clear it out after. I have a second button that will use the session but then it could be ended. It should not be ended to early because there is a go back..
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 34211928
You don't need to actually end the session, just clear out the variable.

i.e.
Session.Remove("Recipients")

Open in new window

0
 

Author Comment

by:mattegol
ID: 34212172
Ok, how about the points?  where should i award them :)
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34212179
Wherever you like :) you can split across multiple posts if you like, but the net result will be the same.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now