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

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?
jammy-d0dgerAsked:
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.

samtran0331Commented:
>>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
jammy-d0dgerAuthor Commented:
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
jammy-d0dgerAuthor Commented:
do you think I should have one <form></form> with all three placeholders inside the form tags?
0
samtran0331Commented:
>>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

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
jammy-d0dgerAuthor Commented:
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
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.