protected void btnSave_OnClick(object sender, EventArgs e) { if (uxFileUpload.FileBytes.Length > 0 ) { int iMaxFileSize = 2097152; if (Request.ContentLength > iMaxFileSize) { exceedErrormessage.Visible=true; //Server.Transfer("Error.aspx"); }
<div class="file-upload"> <asp:Label ID="uiFileUpload" runat="server" AssociatedControlID="uxFileUpload" Text="Select file" /> <p>The maximun file size is 20mb</p> <asp:FileUpload ID="uxFileUpload" runat="server" /> <asp:PlaceHolder ID="exceedErrormessage" Visible="false" runat="server"> <asp:Literal ID="exServerErroemessage" runat="server" Text="The maximum file limit has been exceeded" /> </asp:PlaceHolder> <%--<asp:Label ID="label" runat="server"></asp:Label>--%> <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="uxFileUpload" ErrorMessage="File size should not be greater than 20 mb." OnServerValidate="btnSave_OnClick"></asp:CustomValidator> <asp:Button ID="btnSaveDocument" ValidationGroup="SaveFile" OnClick="btnSave_OnClick" runat="server" Text="Upload" CssClass="button" /> </div>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)