Why a ListView (ASP.NET) comes blank in postback?

Hello,

  I`m intended to create a ListView with CheckBoxes and Images. When I check a CheckBox and click the image a procedure should happen. The problem is: when I click the image a postback is raised but the data in the ListView does not exist anymore. I need to read if the checkbox of the clicked image is checked. I have a ListView in another ASPX and there I can read the ListView's data. What is wrong in my routine?

  In ASPX I have this:

    <asp:ListView ID="lvDelete" runat="server" DataKeyNames="Name">
     <LayoutTemplate>
         <asp:Label ID="itemPlaceHolder" runat="server" />
      </LayoutTemplate>
      <ItemTemplate>
         <asp:CheckBox ID="ckConfirm" runat="server"  />
         <a id="image" href='?Del=<%# Eval("Name") %>' ><img src='<%# "..\\Banners\\" + Eval("Name") %>' alt='<%# Eval("Name") %>' width="350" runat="server" /></a>
       </ItemTemplate>
  </asp:ListView>

In C# this is the binding code:

internal FileSystemInfo[] fsi;
private void LoadBanners()
{
  FileInfo fi = new FileInfo(Server.MapPath("~/Banners/"));
  DirectoryInfo di = fi.Directory;
  fsi = di.GetFiles("*.jpg").Union(di.GetFiles("*.gif")).Union(di.GetFiles("*.png")).ToArray();
  lvDelete.DataSource = fsi;
  lvDelete.DataBind();
}

Thanks,
Marco Castro
MarcoCastroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

keyuCommented:
you must need to write your code inside auto postback to maintain it inside postback

if (!IsPostback)
{

// your code here

}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
keyuCommented:
internal FileSystemInfo[] fsi;
private void LoadBanners()
{
if (!IsPostBack)
{

  FileInfo fi = new FileInfo(Server.MapPath("~/Banners/"));
  DirectoryInfo di = fi.Directory;
  fsi = di.GetFiles("*.jpg").Union(di.GetFiles("*.gif")).Union(di.GetFiles("*.png")).ToArray();
  lvDelete.DataSource = fsi;
  lvDelete.DataBind();
}
}
0
MarcoCastroAuthor Commented:
When I click the image, Page_Load is called and it is not PostBack and at the very begining of Page_Load the LoadView is cleared. Do I need to handle other event of ListView to do the job?
0
MarcoCastroAuthor Commented:
The issue was in the definition fo image. This code:

<a id="image" href='?Del=<%# Eval("Name") %>' ><img src='<%# "..\\Banners\\" + Eval("Name") %>' alt='<%# Eval("Name") %>' width="350" runat="server" /></a>

was generating a call to a new instane of the ASPX file. In this way, the ListView was everytime clear.
0
MarcoCastroAuthor Commented:
From this solution I got the correct explanation of the issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.