Solved

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

Posted on 2007-03-22
5
463 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

12 Experts available now in Live!

Get 1:1 Help Now