?
Solved

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

Posted on 2007-03-22
5
Medium Priority
?
492 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 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