0

I currently a have a popup panel that contains a fileupload control and some other textboxes. What I wanted to do is to create a cancel button that closes the popup panel and reload the page to clear the data from textboxes and fileupload control. I also have an error page wherein if the user uploads a file greater than 15mb, it will throw. The problem is, every time I refresh the page from the server side using Response.Redirect(Request.Url.ToString()), the server still fetches the file that is contained in the fileupload control(Maybe putting it in memory? --Sorry I'm bad at this--) and throws the error page if greater than 15mb. I suspect this is because of the fileupload behavior for any postback it encounter. How can I achieve this close and reload?

Code:

...
      <td>
         <label>Upload: </label>
      </td>
      <td>
         <asp:FileUpload ID="fileUpload" runat="server" CssClass="fileupload"/>
      </td><table>



<br />
      <asp:Button ID="btnSave" ValidationGroup="UpdateSlide" runat="server" Text="Save" CssClass="modal-buttons" OnClick="btnSave_Click"/>
      <asp:Button ID="btnCancel" CausesValidation="false" runat="server" Text="Cancel" CssClass="modal-buttons" OnClick="btnCancel_Click"/>

 <br />

Code Behind:

protected void btnCancel_Click(object sender, EventArgs e){
   Response.Redirect(Request.Url.toString());
}

Error Page Code:

protected void Page_Load(object sender, EventArgs e)
    {
        HtmlMeta meta = new HtmlMeta();
        string path = Request.UrlReferrer.ToString();
        Literal str = new Literal();
        meta.HttpEquiv = "Refresh";
        meta.Content = "5;url=" + path;
        str.Text = "<h1 style='color: red; font-size: xx-large;'>IIS Error 404.13</h1><h2 style='font-size: large'>File upload too large!</h2><p style='color: midnightblue;'>Maximum allowed file size: <b style='color:red;'>15mb</b></p><p>Redirecting...</p>";
        this.Page.Controls.Add(str);
        this.Page.Controls.Add(meta);
    }

Web.config:

<security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="15728640"></requestLimits>
      </requestFiltering>
</security>
<httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="13"/>
      <error statusCode="404" subStatusCode="13" prefixLanguageFilePath="" path="/Error Pages/Error_A.aspx" responseMode="Redirect"/>
      <!--<error statusCode="404" prefixLanguageFilePath=""  path="/Error Pages/ERROR_B.aspx" responseMode="Redirect"/>-->
</httpErrors>

I also tried this from the client side using javascript window.location.reload() but to no avail. (It reloads successfully without posting back to the server but doesn't close the modalpopupextender panel.)

am0r
  • 69
  • 10
  • How do you show modal popup extender - via server or via client code? – Mikhail Tymchuk Nov 10 '15 at 12:54
  • Via server in a gridviewrowcommand event. – am0r Nov 11 '15 at 00:58
  • Okay, so according to an explanation of David Johnstone in (http://stackoverflow.com/questions/2405117/difference-between-window-location-href-window-location-href-and-window-location), `window.location.reload()` and `window.location.href` are entirely different though both of them redirects you to the same page. I came up with `window.location.href` as an answer because of its behavior. (To reload the page without posting back and prevent the file upload control from executing its post back behavior, which is uploading the selected file upon page postback). – am0r Nov 12 '15 at 03:42

0 Answers0