Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Databind ListView not Updating after Postback

Posted on 2009-03-30
10
Medium Priority
?
1,262 Views
Last Modified: 2013-12-17
Hi All,

This is probably really simple, but I just cannot see what I am doing wrong - or not doing!

I have a list of files (FileInfo array databound to a ListView) and it displays fine, all it does is list the file names and links them. - Simple.

The problem is that when I upload a new file and the page performs it's post-back, the ListView does not update. But if I go to the page with the ListView by browsing to it again, the list has updated.

I have seen this issue before, but I was able to 'fix' it by forcing a Response.Redirect to itself. - I don't like this at all!

I also tried to perform a Databind immediately after uploading (see the code below) but the issue still exists - no update after postback.

Any help on this would be appreciated.

Cheers,
James


protected void btnUpload_Click(object sender, EventArgs e)
{
  if (fileUpload.HasFile)
  {
    fileUpload.SaveAs(dirServerPath + @"\" + fileUpload.FileName);
    fileList.DataBind();
  }
}

Open in new window

0
Comment
Question by:JR-Patterson
[X]
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
  • 5
  • 5
10 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 24020700
do you have any update panels on the page?
0
 

Author Comment

by:JR-Patterson
ID: 24020730
Nope. It's all pretty standard stuff.
0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 24020762
when does the new file get added to the array of FileInfo?
0
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 

Author Comment

by:JR-Patterson
ID: 24020807
Well the directory should be looked up every time the page loads, so the array should update. Here is pretty much what is going on in the page load.

Cheers
if (!dir.Exists)
{
  Directory.CreateDirectory(Server.MapPath(docsDir + "/" + currentCompanyID.ToString()));
}
else
{
  files = dir.GetFiles();
  fileList.DataSource = files;
  fileList.DataBind();
}

Open in new window

0
 
LVL 16

Assisted Solution

by:burakiewicz
burakiewicz earned 1200 total points
ID: 24020846
i dont think the way its setup it picks up the new file try this.  
protected void btnUpload_Click(object sender, EventArgs e)
{
  if (fileUpload.HasFile)
  {
    fileUpload.SaveAs(dirServerPath + @"\" + fileUpload.FileName);
    files = dir.GetFiles();
    fileList.DataBind();
  }
}

Open in new window

0
 

Author Comment

by:JR-Patterson
ID: 24020874
Still no luck I'm afraid. Same result. :(
0
 

Accepted Solution

by:
JR-Patterson earned 0 total points
ID: 24020916
This works though!

Should it really be like this? I guess it could just be made into an 'update' method so I don't have to write it over and over... seems silly though.

Thanks a lot for your help.
protected void btnUpload_Click(object sender, EventArgs e)
{
  if (fileUpload.HasFile)
  {
    fileUpload.SaveAs(dirServerPath + @"\" + fileUpload.FileName);
 
    files = dir.GetFiles();
    fileList.DataSource = files;
    fileList.DataBind();
  }
}

Open in new window

0
 
LVL 16

Assisted Solution

by:burakiewicz
burakiewicz earned 1200 total points
ID: 24020924
ok just as a test try something like this ull need to put in the code where it gets the dir

protected void btnUpload_Click(object sender, EventArgs e)
{
  if (fileUpload.HasFile)
  {
 
    fileUpload.SaveAs(dirServerPath + @"\" + fileUpload.FileName);
    
if (!dir.Exists)
{
  Directory.CreateDirectory(Server.MapPath(docsDir + "/" + currentCompanyID.ToString()));
}
else
{
  files = dir.GetFiles();
  fileList.DataSource = files;
  fileList.DataBind();
}
 
  }
}

Open in new window

0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 24020943
it has to be that way.  Because this event
protected void btnUpload_Click(object sender, EventArgs e)
is fired after the page load. so that is why it was never showing up  You should put it in an update method so you only have to code it in 1 place
0
 

Author Comment

by:JR-Patterson
ID: 24020973
Makes sense. I will keep this in mind.

Thanks a lot for your help - greatly appreciated.
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

730 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