jammy-d0dger
asked on
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?
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?
ASKER
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.gi f" 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" /> </p>
<p>
</p>
<!--start table -->
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="wsConnection String">
<itemtemplate>
<asp:HiddenField ID="hfID" runat="server" value=<%#DataBinder.Eval(C ontainer.D ataItem, "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(Co ntainer.Da taItem, "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(Co ntainer.Da taItem, "newsDateSubmit")%>></asp: Label></td >
</tr>
<tr>
<th scope="row">Title: </th>
<td style="width: 404px"><asp:Label ID="lblTitle" runat="server" Text=<%#DataBinder.Eval(Co ntainer.Da taItem, "newsTitle")%>></asp:Label ></td>
</tr>
<tr>
<th scope="row">Abstract: </th>
<td style="width: 404px"><asp:Label ID="lblAbstract" runat="server" Text=<%#DataBinder.Eval(Co ntainer.Da taItem, "newsAbstract")%>></asp:La bel></td>
</tr>
<tr>
<th scope="row">PDF:</th>
<td style="width: 404px"><asp:Label ID="lblPdf" runat="server" Text=<%#DataBinder.Eval(Co ntainer.Da taItem, "newsPdf")%>></asp:Label>< /td>
</tr>
<tr>
<th scope="row"><A href="manageNews.aspx?edit ID=<%#Data Binder.Eva l(Containe r.DataItem , "newsID")%>">Edit This News Item</a></th>
<td style="width: 404px"><strong><A onclick='javascript:window .open("../ newsPdf/<% #DataBinde r.Eval(Con tainer.Dat aItem, "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:wsConnec tionString %>"
SelectCommand="spBstE_getN ewsList" SelectCommandType="StoredP rocedure"> </asp:SqlD ataSource>
<br style="clear:both ">
<p><a href="#">View previous</a> | <a href="#">View next</a> | <a href="index.htm">Back to Welcome page</a></p>
<br style="clear:both ">
</div>
<div id="footer">
<img src="images/footer_bury.gi f" 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.gi f" 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 > 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></t d>
</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:TextBo x></td>
</tr>
<tr>
<th scope="row">PDF: </th>
<td><asp:FileUpload ID="fupAddPDF" runat="server" />
<asp:Label ID="lblAddFileStatus" runat="server" ForeColor="Red"></asp:Labe l>
<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"> </th>
<td><asp:Button ID="btnAddNewSubmit" runat="server" PostBackUrl="manageNews.as px" Text="Submit New Article" OnClick="btnAddNewSubmit_C lick" /></td>
</tr>
</table>
<br style="clear:both ">
<!--end table -->
<br style="clear:both ">
<p><a href="managenews.aspx">Bac k to main News management screen </a><a href="#"></a></p>
<br style="clear:both ">
</div>
<div id="Div5">
<img src="images/footer_bury.gi f" 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.gi f" 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 > 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:Text Box>
</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:TextBo x></td>
</tr>
<tr>
<th scope="row">Current PDF:</th>
<td><asp:Label ID="lblEditPdf" runat="server"></asp:Label >&nbsp ;&nbsp ;<asp:Labe l
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:Labe l>
<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"> </th>
<td><asp:Button ID="btnEditSubmit" runat="server" PostBackUrl="manageNews.as px" Text="Submit Edit" OnClick="btnEditSubmit_Cli ck" /></td>
</tr>
</table>
<br style="clear:both ">
<!--end table -->
<br style="clear:both ">
<p><a href="managenews.aspx">Bac k to main News management screen </a><a href="#"></a></p>
<br style="clear:both ">
</div>
<div id="footer">
<img src="images/footer_bury.gi f" width="728" height="26"></div>
<br style="clear:both ">
</div>
</form>
<!--END MAIN CONTENT -->
<br style="clear:both ">
<!--</asp:PlaceHolder>-->
</body>
</html>
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.gi
<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" /> </p>
<p>
</p>
<!--start table -->
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="wsConnection
<itemtemplate>
<asp:HiddenField ID="hfID" runat="server" value=<%#DataBinder.Eval(C
<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(Co
</tr>
<tr>
<th scope="row">Creation Date: </th>
<td style="width: 404px"><asp:Label ID="lblDateSubmit" runat="server" Text=<%#DataBinder.Eval(Co
</tr>
<tr>
<th scope="row">Title: </th>
<td style="width: 404px"><asp:Label ID="lblTitle" runat="server" Text=<%#DataBinder.Eval(Co
</tr>
<tr>
<th scope="row">Abstract: </th>
<td style="width: 404px"><asp:Label ID="lblAbstract" runat="server" Text=<%#DataBinder.Eval(Co
</tr>
<tr>
<th scope="row">PDF:</th>
<td style="width: 404px"><asp:Label ID="lblPdf" runat="server" Text=<%#DataBinder.Eval(Co
</tr>
<tr>
<th scope="row"><A href="manageNews.aspx?edit
<td style="width: 404px"><strong><A onclick='javascript:window
</tr>
<!--end table -->
</table>
<br style="clear:both ">
<br style="clear:both ">
</itemtemplate>
</asp:Repeater>
<asp:SqlDataSource ID="wsConnectionString" runat="server" ConnectionString="<%$ ConnectionStrings:wsConnec
SelectCommand="spBstE_getN
<br style="clear:both ">
<p><a href="#">View previous</a> | <a href="#">View next</a> | <a href="index.htm">Back to Welcome page</a></p>
<br style="clear:both ">
</div>
<div id="footer">
<img src="images/footer_bury.gi
<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.gi
<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 > 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></t
</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:TextBo
</tr>
<tr>
<th scope="row">PDF: </th>
<td><asp:FileUpload ID="fupAddPDF" runat="server" />
<asp:Label ID="lblAddFileStatus" runat="server" ForeColor="Red"></asp:Labe
<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"> </th>
<td><asp:Button ID="btnAddNewSubmit" runat="server" PostBackUrl="manageNews.as
</tr>
</table>
<br style="clear:both ">
<!--end table -->
<br style="clear:both ">
<p><a href="managenews.aspx">Bac
<br style="clear:both ">
</div>
<div id="Div5">
<img src="images/footer_bury.gi
<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.gi
<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 > 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:Text
</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:TextBo
</tr>
<tr>
<th scope="row">Current PDF:</th>
<td><asp:Label ID="lblEditPdf" runat="server"></asp:Label
ID="lblEditPdfView" runat="server" Text="Label"></asp:Label><
</tr>
<tr>
<th scope="row">New PDF: </th>
<td><asp:FileUpload ID="fupEditPDF" runat="server" />
<asp:Label ID="lblUploadStatus" runat="server" ForeColor="Red"></asp:Labe
<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"> </th>
<td><asp:Button ID="btnEditSubmit" runat="server" PostBackUrl="manageNews.as
</tr>
</table>
<br style="clear:both ">
<!--end table -->
<br style="clear:both ">
<p><a href="managenews.aspx">Bac
<br style="clear:both ">
</div>
<div id="footer">
<img src="images/footer_bury.gi
<br style="clear:both ">
</div>
</form>
<!--END MAIN CONTENT -->
<br style="clear:both ">
<!--</asp:PlaceHolder>-->
</body>
</html>
ASKER
do you think I should have one <form></form> with all three placeholders inside the form tags?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
Cheers for flagging the issue!
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...