I am using ASP:FileUpload Control for uploading the PDF files. I have limited the upload file size to 1MB in Web.Config like this.
<system.web>
<httpRuntime maxRequestLength="1024" executionTimeout="360"/>
</system.web>
ASPX code
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebpageUpload.WebForm1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="Ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
Normal File Upload...
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Clear" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
Here the main issue is, When i upload a file more than 1 MB and click on Clear button, I am getting "Internet Explorel Cannot display this webpage."
Please find the Image for reference..
Thanks in advance...
When you set that value in web.config you tell IIS that you are going to be exceptioning on that condition. That means a YSOD. You need to either catch that exception and handle it gracefully or raise the limit and check it by hand. Unfortunately, with the file upload control, there is no way to check the file size ahead of time before the upload is initiated.
If you want to restrict the user to upload files to less than 1 MB, you have to put in the following condition and check the file size before uploading.
if (FileUpload2.FileContent.Length > 1048576)
{
//File Size is greater than 1 MB
}
Related
Although, i write a code with all required lines in Asp.net , the Autocomplete extender not working ,i dont able to find the reason anyone can teach with code.
The Error i faced
Error 3 Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified.
Error 4 Unknown server tag 'asp:ScriptManager'.
Error 4 Element 'ScriptManager' is not a known element. This can occur if there is a compilation error in the Web site.
Error 5 Unknown server tag 'asp:AutoCompleteExtender'.
Error 5 Element 'AutoCompleteExtender' is not a known element. This can occur if there is a compilation error in the Web site.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>AJAX AutoComplete</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCity"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000"
ServiceMethod="GetCity" >
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>
AjaxControlToolkit i installed . and i want to excecute autocomplete textbox code
I think you have register you ajaxtoolkit as ajaxtoolkit tag on page so instead of using tag you should use tag. For example.
<AjaxControlToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCity"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000"
ServiceMethod="GetCity" >
Yes its workin now !! becoz of the auto generated bin folder in Vs .. and also i changed the ajax toolkit version 1.0.20229 For Visual studio 2005...Thank you so much for every one .. your replies helped me lot..
I found AjaxFileUpload in the toolkit when searching for ways to upload multiple files.
I used NuGet to install.
Added <%# Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%> to the top of the page.
Ensured web.config has the reference:
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
Where I presume the the upload button should be, I get a black box, when I run the page. The preview does show up correctly.
I did try it in a completely empty page (no master page or anything) and I get the same result.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="School_Scheduler_2.Associates.test" %>
<%# Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<ajaxToolkit:AjaxFileUpload runAt="server" ID="multiUpload" />
</form>
</body>
</html>
Any suggestions?
Answer Since My Account Is Too Noob to the Post Answer Myself
This explains it: https://ajaxcontroltoolkit.codeplex.com/workitem/27493
Long story short: The Ajax Tool Kit does not like the vanilla ScriptManager. It insists on using their own ToolkitScriptManager.
This causes havoc with my MasterPages (I put the script manager on there to save me from adding it everywhere), but at least I know now and can start scheming possible solutions.
try this
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div align="center">
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpg,jpeg,png,gif"
MaximumNumberOfFiles="10" OnUploadComplete="File_Upload"
Width="500px" />
Old question, but make sure to debug any javascript errors. Any errors will cause the described black button.
If you have any client side code that runs on OnClientUploadCompleteAll=, but fail to copy this code to a new page if you are copy/pasting the AjaxFileUpload control, you get a javascript error and it fails to render the control at this point, just leaving you with the black button.
I have been trying to solve this problem for several weeks now and it is getting really frustrating. Basically i have a simple project which includes one master page and one content page. the following code is what is found in the content page
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="ButtonContent"
onclick="Button1_Click" />
</asp:Content>
The button is bound to a simple event. A break point is set to detect whether the event fired as expected. The event does not fire when a form is placed above the content place holder.
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<form></form>
</div>
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div>
</div>
</form>
</body>
</html>
however the event is fired when the form is removed or place below the content place holder. On the other hand, on some machines i have found that it does not matter if a form is placed before the content place holder. I have tried this project on 4 machines (three windows 7 and one xp) it has worked regardless of form placement on two machines and has been subject to form placement on the other two.
Could some one please point me to some setting which could solve this problem or offer any advice to solve my problem. I need a form before the content place holder so removing is out of the question. It would also make sense that some sort of setting is preventing the project from working correctly on another machine
per HTML spec, you can not have form inside form. If I remember correctly some browsers break when you have this kind of structure. I think IE works fine.
If you need another form, put it outside of the <form id="form1" runat="server">
- above it, specifically. That is valid.
For a company we are making 2 different sites, now one of those sites got an flv player in it and streams local flv files to the clients with the webpart from: http://www.aspnetflashvideo.com
Now on the second site we also want an flv player but this one without local files, it should stream the flv file from the other website to the users of this second website.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="ASPNetFlashVideo.NET3" Namespace="ASPNetFlashVideo" TagPrefix="ASPNetFlashVideo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo1" runat="server"
VideoURL="http://flv.dumpert.nl/7649709f_YTDL_1.flv.flv" >
</ASPNetFlashVideo:FlashVideo>
</div>
</form>
</body>
</html>
Is this possible and how? Because it doesn't seem to work with the webpart.
I may be completely off track here, but it looks like your Video Url has the file extension in twice... Try:
<ASPNetFlashVideo:FlashVideo ID="FlashVideo1" runat="server"
VideoURL="http://flv.dumpert.nl/7649709f_YTDL_1.flv" >
</ASPNetFlashVideo:FlashVideo>
i'm creating a brand new masterpage with VS2010 Beta 2 and I get this warning (that causes me errors in the content pages):
Validation (XHTML 1.0 Transitional):
Content is not supported outside
'script' or 'asp:content' regions.
The masterpage's code :
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Bob.master.cs" Inherits="TShirtFactory.Web.All.Core.lib.masterpage.Bob" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
As you can see, it's the default masterpage generated code. I get the warning when I hover the tag at top. Does anybody have an idea of what's going on ?
Thank you
In my case the error has gone after removing masterPageFile attribute from the Page-section in the web.config file:
<configuration>
<system.web>
<pages styleSheetTheme="mystyle" masterPageFile="~/myMaster.master" />
</system.web>
</configuration>
Or, if you need this attribute in the web.config file, just add empty MasterPageFile to you master page:
<%# Master Language="VB" AutoEventWireup="false" CodeFile="mySecondMaster.master.vb" Inherits="mySecondMaster" MasterPageFile="" %>
It's simple... Visual Studio is bonkers. Actually, the truth is that it can't possibly validate some markup simply because much of it is dynamic. For instance, in my project I have a constant warning about the lack of a <title> tag because it's added dynamically. Bottom line: the XHTML validator does not really know much about ASP.NET code.