tags:

views:

24

answers:

1

I can't figure out why this line of code

Image1.ImageUrl = displayPath + photoFileList[index].ToString();

works in the Button1 click event but not in the btnNext click event (after clicking button1 to load the data).

if i comment out the line in button1 it won't work in btnNext after clicking button1

    public List<string> photoFileList = new List<string>();
    public int index = 0;
    public string loadPath = "\\\\intranet.org\\Photo Album\\Employees\\";
    public string displayPath = "////intranet.org//Photo Album//Employees//";


    protected void Button1_Click(object sender, EventArgs e)
    {

        DirectoryInfo di = new DirectoryInfo(loadPath);
        FileInfo[] rgFiles = di.GetFiles("*.JPG");
        foreach (FileInfo fi in rgFiles)
        {

            photoFileList.Add(fi.Name);
        }


// this next line works here if i uncomment it but it won't work in btnNext click
//Image1.ImageUrl = displayPath + photoFileList[index].ToString();




    }
    protected void btnNext_Click(object sender, EventArgs e)
    {


        Image1.ImageUrl = displayPath + photoFileList[index].ToString();

    }
A: 

You are getting the directory info in the button1 click, but since you are not storing it in say the session info it is getting lost on the next request from the client, the next button click. Try storing the string list into a session variable and retrieving it in the next click event.

Decker97