Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to pass arraylist between updatepanels

Posted on 2010-11-25
11
367 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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