.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

UpdatePanel and FileUpload

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
Hi, i have wide customer table that i handle with a big DetailView nested inside an UpdatePanel for faster interaction. Works like a charm. Now they ask me to allow the user to upload a file, but when i add it in the detail view and i save data i get no file at all, as if putting it into an updatepanel do not allow him to send the file any more. Is there some setting i have to put so to make it work ? thanks in advance, Fabrizio

View Complete Post

More Related Resource Links

Problem in "Upload a picture into data base" because is in

Hi guys. I can upload a picture into database by this code correctly in a web page without "UpdatePanel": ******************************** SqlConnection connection = null; try { Byte[] imgByte = null; if (FileUpload.HasFile && FileUpload.PostedFile != null) { HttpPostedFile File = FileUpload.PostedFile; imgByte = new Byte[File.ContentLength]; File.InputStream.Read(imgByte, 0, File.ContentLength); } // Insert the employee name and image into db string conn = "Data Source=PC5;Initial Catalog=LaptopStore;Integrated Security=True"; connection = new SqlConnection(conn); connection.Open(); string sql = "INSERT INTO test(image) VALUES(@image) SELECT @@IDENTITY"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@image", imgByte); int id = Convert.ToInt32(cmd.ExecuteScalar()); lblResult.Text = String.Format("Employee ID is {0}", id); } catch { lblResult.Text = "There was an error"; } finally { connection.Close(); } ******************************************** But when I want to use this code in a

fileupload in UpdatePanel

Hi there, Can anybody tell me why this is working but not with UpdatePanel (commented lines here)?<body> <form id="form1" runat="server"> <div> <!--<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> --> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <!--<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate>--> <hr /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <asp:FileUpload ID="FileUpload1" runat="server" /><br /> <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> <hr /> <!--</ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel>--> <br /> <br /> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Labe

FileUpload and UpdatePanel: FileUpload.HasFile is always FALSE.

Hello. I'm developing an ASP.NET application with C# and Visual Studio 2008 SP1. I'm using WebForms. I have an ASPX page with two UpdatePanels, one on the left that holds a TreeView and other on the right where I load dynamically user controls. One user control, that I used on right panel, has a FileUpload control and a button to save that file on server. The ascx code to save control is:     <asp:UpdatePanel ID="UpdatePanelBotons" runat="server" RenderMode="Inline"      UpdateMode="Conditional">    <ContentTemplate>     <asp:Button ID="Save" runat="server" Text="Guardar"         onclick="Save_Click" CssClass="button" />     </ContentTemplate>     <Triggers>      <asp:PostBackTrigger ControlID="Save" />     </Triggers>    </asp:UpdatePanel> I make a full postback to upload the file to the server and save it to database. But I always getting False on FileUpload.HasFile. I problem is the right UpdatePanel. I need it to load dynamically the user controls. This panel has three UpdatePanels to load the three user controls that I

FileUpload in DetailsView fails with UpdatePanel



I'm developing a project in ASP.NET C#, with SQL Server Express 2005, on Windows Vista.

I have a GridView, and a DetailsView on an aspx page.

The GridView displays all items in a database that has a certain ProductID (The items is Pictures)

The DetailsView displays the selected row of the GridView.

In the DetailsView I have 3 FileUpload controls, for 3 different size of images.

My update functionallity works just fine. I catch the OnUpdating event of it's ObjectDataSource, and uses FindControl to get each FileUpload Control, and executes the FileUpload.SaveAs() method if the user provided a new Image.

My problem occurs when I want to Insert a new image. No matter what - all my FileUpload's HasFile property is always false.

I was trying different things, and then I removed the UpdatePanel from the page. That solved my problem, but I really want to use the UpdatePanel. What I found really strange is, that the code very much identic to the code for inserting, works fine when I'm updating.

I use kind of the same idea as provided in this: http://www.asp.net/Learn/DataAccess/tutorial56cs.aspx?tabid=63 article. I just have an UpdatePanel arround both the GridView and DetailsView.

Any ideas on what might be wrong?

FileUpload inside the UpdatePanel


I am  facing some problem when I am trying upload a file when fileUpload control is inside an UpdatePanel. As I am checking whether the file is selected or not before upload, I found every time the fileUpload's selected file is lost. What I guess, when I am clicking the upload button which is also the trigger for that updatePanel, is creating a async postback and the selected file is lost, but I dont think this problem is beyond solution.So, anybody please help me with some solution. Please ping here also if any follow up info needed for answering

thanks in advance

Server side validation of Fileupload control not working



I've tried this method in my code behind to try and validate that the Fileupload control has a file or not. I get the error message the the event "Server Validate" cannot be found. Can anyone tell why? Thanks.

Public Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

' Get file name

        Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload)

        Dim UploadFileName As String = uploadAvatar.PostedFile.FileName

        If UploadFileName = "" Then
            ' There is no file selected
            args.IsValid = False
            Dim Extension As String = UploadFileName.Substring(UploadFileName.L

UpdatePanel is not a known element - message when upgrading to 1.0 ajax


It worked on one of my old pages.  I change the web.config, renamed all the <asp.

On some aspx page it doesn't recognize the updatepanel.  It only does on one page.  If I create a new aspx page with a different name - then it works.

Should I just create a new web project ajax - then copy all my code into there?  Or is there a way to get those old pages to recognize the new ajax controls?

Gridview inside updatepanel


I am displaying large amount of data in gridview,the gridview placed within updatepanel,every 1sec i am refreshing updatepanel using ajax timer.my problem is while displaying large data the cpu performance is low,pls give idea to increase cpu performance..

Wicked Code: UpdatePanel Tips and Tricks


Jeff Prosise explains when it's better to use UpdatePanel and when it's better to use asynchronous calls to WebMethods or page methods instead.

Jeff Prosise

MSDN Magazine June 2007

How do you insert a google map into an ajax updatepanel?


I have built a site that I am using google maps on.  The default page has a google map with info windows containing links and all works great... until a user clicks on the link in the info window.  Doing so takes them to a community page that I have built.  On this community page, I have an ajax update panel that has 2 panels nested inside of it with the visibility set for one to be on and the other off.  The default panel shows community photos, and the second panel I want to show the google map and common directions to the community.  In testing, my buttons to switch the visibility of the panels works great as it should without postback, but when I try to add the map to its panel, it does not show up.  I am new to ajax as well as google maps and I'm not sure why the same code would work fine on my default page but not the community page.  The only obvious thing I can assume is because the community page map is in an update panel.  

How do you insert a google map into and ajax updatepanel and have it work correctly?  Many thanks in advance. 

ModalPopup/UpdatePanel from codebehind, inconsistent behavior onClick


First post bear with me please:

I have a simple form with a list of linkbuttons, each fires the same onclick event which sets an indicator image.  I have a dummy button with style="display:none" which I have set as the TargetControlID of the modal.

onClick event from the imagebutton, the modal is shown via modal.Show().  The cancel button inside the modalpopup fires an event which turns off the indicator image and hides the modal via modal.Hide(). 

The events fire perfectly, it's very simple!  Although after doing some testing I noticed the modalpopup is not presented after the 6-10th cycle of clicking the open event, then clicking cancel.  The grey background appears but it is behind the main panel and the modal is either presented behind this or is just simply not displaying. 

I spent hours researching various methods, implemented the CancelControlID to see if it was somehow tied to my call of modal.Hide() that fails.

This occurs with an updatepanel only.  The behaviour is much cleaner this way, so I would hope to be able to implement this.  I have basically eliminated everything but these two events!  Please help

UpdateProgress with a dummy updatepanel not working


I have a Submit button and some functionality like updating DB and fetching next page in the button click event. This process takes a long time and I want to display a message saying "Progress...." right after clicking the botton. I want to do the same in 20 other pages. So, best way to do it wd be to put the modalpopup MPE or an Updateprogress in a usercontrol or in master page. I first tried putting both of these on the page itself to test and see and neither worked.

I tried using Update progress control with a dummy updatepanel and giving the Submit button as Asyntrigger to the dummy updatepanel. I have also tried using MPE but it didnt work either. Below is an example of what i did..

<asp:UpdatePanel ID="UpdatePanel1" runat=server><contenttemplate><triggers><asyntrigger ID= "Submit"> /> /> />

<asp:updateprogress ID="Progress1" unat=server AssociatedUpdatePanelID="UpdatePanel1"><Progresstemplate>Progress.... />/>

<asp:button ID= "Submit" runat=server >

I have nothing for updateprogress in code behind. Am i missing or doing somethign wrong here? Any help would be appreciated.

FileUpload Class SaveAs, how can you overwrite?

Hello all,

I'm trying to use 2.0 class, FileUpload. 
Namespace: System.Web.UI.WebControls
Class FileUpload

Anyway, in my code can save the file to the server

FileUpload1.SaveAs(SavePath + FileName)

Problem is I can't find a way to overwrite the file.  When I try and run the program again is says the file is already in use that a process has access to it.

Is thre a proper way to release control of whatever it grabbing hold of it?  In .Net I don't have to destroy my objects right?
Or is there a way to specificly overwrite the file? It seems that SaveAs does that.  Just trying to figure out why I can upload this text file, but sometimes only once and then I have to code in to check to see if it exists then rename it.

UpdatePanel in a Webpart


I'm exploring the usage of UpdatePanels in WebParts for MOSS 2007. The code I have so far for adding a test update panel is this:

                LinkButton goButton;
                goButton = new LinkButton();
                goButton.ID = "butGo";
                goButton.Text = "Go";
                goButton.Command += new CommandEventHandler(goButton_Command);
                goButton.Click += new EventHandler(goButton_Click);

file upload in Create User Wizard Created User event with UpdatePanel Tag wont work?



In my Create User Wizard1 Created User Wizard Event, I am collecting extra information from text boxes and allowing

the user to uplad a file.



I have put the Submit button within an Update Panel Tag but since I have done this it does not work.

Is there a way round it. In this situation would you use a trigger.?


<br />

  <asp:UpdatePanel ID="UpdatePanel2" runat="server">

  <asp:Button ID="StepNextButton" runat="server"  CommandName="MoveNext"  align="middle"
                                            Text="Submit my Profile" />

Total newbie question: Calling jQuery in an UpdatePanel?



Please forgive this ignorant question - I've used ASP.NET AJAX a good deal but I'm new to jQuery.  Specifically, is it possible to call or create jQuery events on the fly via an UpdatePanel?  For example, calling a jQuery modal or animating a Label (or <div> contained Literal), etc.

If anyone has any advice or could point me to some easy tutorials on mixing ASP.NET AJAX and jQuery, I'd greatly appreciate it. 



FileUpload error: Object reference error


I have a FormView with a FileUpload to upload an image in a database.

I keep getting an object reference error.(view code)

I am using this same script to upload the image to the database, but when I try to update the file upload I get the error.    

string strFilePath=Server.MapPath("\\images\\"+fupdImage.FileName);

        Byte[] image=null;
        HttpPostedFile imgVid=FileUpload.PostedFile;

        image=new Byte[imgVid.ContentLength];//Object reference not set to an instance of an object.

        if(FileUpload.HasFile) {
        string imageFile=FileUpload.PostedFile.FileName;
        int index=imageFile.LastIndexOf(".");
        string fileFormat=imageFile.Substring(index+1);


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend