Solved

FileUpload and PlaceHolders don't mix in ASP.NET?

Posted on 2007-03-22
5
469 Views
Last Modified: 2008-07-03
Right, here's a weird one.

I have a single aspx page that manages news articles on a site.  There are three PlaceHolders in the script, each of which contains a server-side form.  Two of these forms contains a FileUpload control.  Except only one of the FileUpload controls works, the other one always shows 'False' for the HasFile property.  If I reposition the placeholders, I find that the placeholder that appears last in the aspx file, always works, the one above doesn't.


I'm done with pulling my hair on what feels like the millionth weird thing to occur in ASP.NET.  Anyone had similar problem and solved it?
0
Comment
Question by:jammy-d0dger
  • 3
  • 2
5 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 18772921
>>are three PlaceHolders in the script, each of which contains a server-side form.
could you post your aspx page? i don't see how you're getting away with having 3 "server-side" forms... .Net only allows one form on the page to have the runat=server tag...
0
 

Author Comment

by:jammy-d0dger
ID: 18772976
it's a big file:  I think I'm getting away with it because only one placeholder is ever visible at any one time:

Here's the body of the script:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Administration Area</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
      <!--<asp:PlaceHolder id="phNewsList" Runat="Server" Visible=False>-->

<form id="form1" runat="server">
    <div id="main">
<!--START NON-FLASH -->
<div id="header"><img src="images/header_bury.gif" alt="Administration Area" width="728" height="105"></div>

<div id="nav">
<ul>
<li id="otherpage"><a href="index.htm" title="Welcome page" accesskey="1">Welcome page</a></li>
<li id="thispage"><a href="managenews.aspx" title="News section" accesskey="2">News admin</a></li>
<li id="Li1"><a href="managemaps.aspx" title="Maps section" accesskey="3">Maps admin</a></li>
</ul>
<br style="clear:both ">
</div>

<!--START MAIN CONTENT -->
<div id="left">
<h1>News Management Screen</h1>
<p>
    <asp:Button ID="btnAddNew" runat="server" OnClick="btnAddNew_Click" Text="Click here to ADD new article" />&nbsp;</p>
    <p>
        </p>
<!--start table -->

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="wsConnectionString">
<itemtemplate>
    <asp:HiddenField ID="hfID" runat="server" value=<%#DataBinder.Eval(Container.DataItem, "newsID")%> />
<table width="600" border="1" align="left" cellpadding="5" cellspacing="5" bordercolor="#999999" bgcolor="#FFFFFF" class="table_style" summary="news article:">
  <tr>
    <th width="148" scope="row">ID:</th>
    <td style="width: 404px"><asp:Label ID="lblID" runat="server" Text=<%#DataBinder.Eval(Container.DataItem, "newsID")%>></asp:Label></td>
  </tr>
  <tr>
    <th scope="row">Creation Date: </th>
    <td style="width: 404px"><asp:Label ID="lblDateSubmit" runat="server" Text=<%#DataBinder.Eval(Container.DataItem, "newsDateSubmit")%>></asp:Label></td>
  </tr>
  <tr>
    <th scope="row">Title: </th>
    <td style="width: 404px"><asp:Label ID="lblTitle" runat="server" Text=<%#DataBinder.Eval(Container.DataItem, "newsTitle")%>></asp:Label></td>
  </tr>
  <tr>
    <th scope="row">Abstract: </th>
    <td style="width: 404px"><asp:Label ID="lblAbstract" runat="server" Text=<%#DataBinder.Eval(Container.DataItem, "newsAbstract")%>></asp:Label></td>
  </tr>
  <tr>
    <th scope="row">PDF:</th>
    <td style="width: 404px"><asp:Label ID="lblPdf" runat="server" Text=<%#DataBinder.Eval(Container.DataItem, "newsPdf")%>></asp:Label></td>
  </tr>
  <tr>
    <th scope="row"><A href="manageNews.aspx?editID=<%#DataBinder.Eval(Container.DataItem, "newsID")%>">Edit This News Item</a></th>
    <td style="width: 404px"><strong><A onclick='javascript:window.open("../newsPdf/<%#DataBinder.Eval(Container.DataItem, "newsPdf")%>","viewPDF")' href="#">View This PDF</a></strong></td>
  </tr>
<!--end table -->

</table>
<br style="clear:both ">
<br style="clear:both ">

</itemtemplate>
</asp:Repeater>
<asp:SqlDataSource ID="wsConnectionString" runat="server" ConnectionString="<%$ ConnectionStrings:wsConnectionString %>"
    SelectCommand="spBstE_getNewsList" SelectCommandType="StoredProcedure"></asp:SqlDataSource>


<br style="clear:both ">
<p><a href="#">View previous</a>&nbsp; | &nbsp;<a href="#">View next</a>&nbsp; | &nbsp;<a href="index.htm">Back to Welcome page</a></p>
<br style="clear:both ">
</div>
<div id="footer">
<img src="images/footer_bury.gif" width="728" height="26"></div>
<br style="clear:both ">
</div>
</form>

<!--END MAIN CONTENT -->
<br style="clear:both ">
<!--</asp:PlaceHolder>-->

<!--<asp:PlaceHolder id="phNewsAdd" Runat="Server" Visible=False>-->
 <form id="frmAddNews" runat=server>
<div id="main">
<!--START NON-FLASH -->
<div id="hedaer"><img src="images/header_bury.gif" alt="Administration Area" width="728" height="105"></div>

<div id="nav">
<ul>
<li id="otherpage"><a href="index.htm" title="Welcome page" accesskey="1">Welcome page</a></li>
<li id="thispage"><a href="managenews.aspx" title="News section" accesskey="2">News admin</a></li>
<li id="otherpage"><a href="managemaps.aspx" title="Maps section" accesskey="3">Maps admin</a></li>
</ul>
<br style="clear:both ">
</div>
<!--START MAIN CONTENT -->
<div id="left">
<h1>News Management Screen &gt; Add New Article </h1>
<!--start table -->
<table width="600" border="1" align="left" cellpadding="5" cellspacing="5" bordercolor="#999999" bgcolor="#FFFFFF" class="table_style" summary="news article:">
  <tr>
    <th width="148" scope="row">ID:</th>
    <td width="411"><asp:Label ID="lblAddID" runat="server" Text="">TBC</asp:Label></td>
  </tr>
  <tr>
    <th scope="row">Title: </th>
    <td><label>
      <asp:TextBox ID="txtAddTitle" runat="server" MaxLength="50" Text=""></asp:TextBox>
    </label></td>
  </tr>
  <tr>
    <th scope="row">Abstract: </th>
    <td><asp:TextBox ID="txtAddAbstract" runat="server" maxlength="1000" Height="64px" TextMode="MultiLine" Width="419px"></asp:TextBox></td>
  </tr>
  <tr>
    <th scope="row">PDF: </th>
    <td><asp:FileUpload ID="fupAddPDF" runat="server" />
        <asp:Label ID="lblAddFileStatus" runat="server" ForeColor="Red"></asp:Label>
      <label>
      <br>
      Note: Leave this blank if you do not wish to attach a PDF to this news item.</label></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><asp:Button ID="btnAddNewSubmit" runat="server" PostBackUrl="manageNews.aspx" Text="Submit New Article" OnClick="btnAddNewSubmit_Click" /></td>
  </tr>
</table>
<br style="clear:both ">
<!--end table -->
<br style="clear:both ">
<p><a href="managenews.aspx">Back to main News management screen </a><a href="#"></a></p>
<br style="clear:both ">
</div>
<div id="Div5">
<img src="images/footer_bury.gif" width="728" height="26"></div>
<br style="clear:both ">
</div>
</form>
<!--END MAIN CONTENT -->
<br style="clear:both ">   
<!--</asp:PlaceHolder>-->

<!--<asp:PlaceHolder id="phNewsEdit" Runat="Server" Visible=False>-->
    <form runat=server id=frmEditNews method=post>
    <asp:HiddenField ID="hfID" runat="server" value="" />
<div id="main">
<!--START NON-FLASH -->
<div id="header"><img src="images/header_bury.gif" alt="Administration Area" width="728" height="105"></div>

<div id="nav">
<ul>
<li id="otherpage"><a href="index.htm" title="Welcome page" accesskey="1">Welcome page</a></li>
<li id="thispage"><a href="managenews.htm" title="News section" accesskey="2">News admin</a></li>
<li id="otherpage"><a href="managemaps.htm" title="Maps section" accesskey="3">Maps admin</a></li>
</ul>
<br style="clear:both ">
</div>

<!--START MAIN CONTENT -->
<div id="left">
<h1>News Management Screen &gt; Edit News Article </h1>
<!--start table -->
<table width="600" border="1" align="left" cellpadding="5" cellspacing="5" bordercolor="#999999" bgcolor="#FFFFFF" class="table_style" summary="news article:">
  <tr>
    <th width="148" scope="row">ID:</th>
    <td width="411"><asp:Label ID="lblEditID" runat="server" Text=""></asp:Label></td>
  </tr>
  <tr>
    <th scope="row">Title: </th>
    <td><label>
      <asp:TextBox ID="txtEditTitle" runat="server" MaxLength="50" Text="Testtext"></asp:TextBox>
    </label></td>
  </tr>
  <tr>
    <th scope="row">Abstract: </th>
    <td><asp:TextBox ID="txtEditAbstract" runat="server" maxlength="1000" Height="64px" TextMode="MultiLine" Width="419px"></asp:TextBox></td>
  </tr>
  <tr>
    <th scope="row">Current PDF:</th>
    <td><asp:Label ID="lblEditPdf" runat="server"></asp:Label>&amp;nbsp;&amp;nbsp;<asp:Label
            ID="lblEditPdfView" runat="server" Text="Label"></asp:Label></td>
  </tr>
  <tr>
    <th scope="row">New PDF: </th>
    <td><asp:FileUpload ID="fupEditPDF" runat="server" />
        <asp:Label ID="lblUploadStatus" runat="server" ForeColor="Red"></asp:Label>
      <label>
      <br>
      Note: Leave this blank if you wish to keep the Current PDF for this news item.</label></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><asp:Button ID="btnEditSubmit" runat="server" PostBackUrl="manageNews.aspx" Text="Submit Edit" OnClick="btnEditSubmit_Click" /></td>
  </tr>
</table>
<br style="clear:both ">
<!--end table -->
<br style="clear:both ">
<p><a href="managenews.aspx">Back to main News management screen </a><a href="#"></a></p>
<br style="clear:both ">
</div>
<div id="footer">
<img src="images/footer_bury.gif" width="728" height="26"></div>
<br style="clear:both ">
</div>
</form>

<!--END MAIN CONTENT -->
<br style="clear:both ">   
<!--</asp:PlaceHolder>-->


</body>
</html>
0
 

Author Comment

by:jammy-d0dger
ID: 18773006
do you think I should have one <form></form> with all three placeholders inside the form tags?
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 18773102
>>do you think I should have one <form></form> with all three placeholders inside the form tags?

I wouldn't be surprised if the multiple form tags is what is making it act weird.
I would see if using only one form makes a difference.
You can just show/hide the placeholders...or even wrap each of the "forms" you have now inside asp:panel controls instead (replace your "forms" with asp:panel's)...and then you can toggle which panel is visible...
0
 

Author Comment

by:jammy-d0dger
ID: 18773264
that's got it.  So that's another valuable lesson learnt.  Only one server-side form even if they're in different placeholders and never displayed at the same time.  Wrap all three placeholders in one form and it's all fixed.

Cheers for flagging the issue!
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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

22 Experts available now in Live!

Get 1:1 Help Now