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

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

FileUpload in DetailsView fails with UpdatePanel

Posted By:      Posted Date: October 09, 2010    Points: 0   Category :ASP.Net


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?

View Complete Post

More Related Resource Links

UpdatePanel and FileUpload

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

Issue accessing textbox controls nested within a DetailsView within an UpdatePanel

I have a couple of textboxes nested with a detailsview, within an updatepanel.  When I try and access them from the code behind, it returns a null value as if they don't exist.  Can't figure out why that would be.ASPX code is: <asp:UpdatePanel ID="upSpecificShout" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" > <ContentTemplate> <asp:DetailsView ID="dvSingleShout" DataSourceID="sdsSingleShout" runat="server" AutoGenerateRows="false" OnDataBound="SetDVIcons" HeaderStyle-CssClass="noDisplay" > <EmptyDataTemplate> <p class="Watermark"> The panel on the left shows a list of everything you've shouted. (Your replies to other shouts are highlighted in blue/green.) </p> <p class="Watermark"> This right hand panel will show specific shouts with a list of replies etc.. Just do a little click on a shout title to display more detail here. </p> <p class="Watermark">

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 Issue in DetailsView

Hi every1, I'm using FileUpload Control to update a table and it works fine but, the issue arise when not entering a file, then the record set the picture field value to NULL Anybody please help.My Head is gonna explode

Problem with Editing image inside DetailsView inside UpdatePanel



I have a problem and I really hope you'll be able to help me.

I'm trying to add and edit an image which is located in a detailsview which is inside an UpdatePanel. After I read relevant topics in the forum I installed the Ajax Control Toolkit. Below is my source code. When I used it only for insert new image it worked great. The problem caused when I tried to implement it on the Edit mode, i.e. when I tried to edit the image and upload a different image.  Unfortunately it didn't work as I hoped. Nothing happend and the image hasn't been changed. I also tried to change the IDs (AsyncFileUpload ID) to be the same in both places but it didn't work either.

The source code:

<asp:DetailsView ID="dvMovie" runat="server" Height="50px" Width="695px"
                    AutoGenerateRows="False" DataSourceID="sdsMovieById"      
                     BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"

ToolkitScriptManager fails on updating UpdatePanel


Hello everyone,

this is my first post in this forum, even though I often search for helps and clarifications over its threads. And many times they are definitely useful!!

I had a <asp:ScriptManager> in may MasterPage, wich was used to manage various UpdatePanels I have either in Content pages or in  MasterPage.

Today I inserted a CalendarExtender, so I had to replace the ScriptManeger with the AJAX ToolkitScriptManager.

At the beginning it seemed to work fine (the calendar pop up and others controls got updated properly). Then I noticed that the nodes in various TreeView are not expanding any more. 

The TreeViews objects are placed inside an UpdatePanel, in order to expand each node without refreshing the whole content page. And, while a node expands, an UpdatePanel containing a GridView in the content page gets updated.

Now, with the new ScriptManager they do not expand, but when clicking on a single node the GridView is updated properly.

Here some pieces of code:

<asp:ToolkitScriptManager ID="SM_Tree" runat="server" EnablePartialRendering="true" EnableScriptGlobalization="true" CombineScripts="false">

TSM in MasterPage


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

Master-Detail with the GridView, DetailsView and jQuery's ThickBox

One more article about grids from Matt Berseth. This time he shows how to create master-detail with the gridview, detailsview and jQuery's ThickBox. He writes:
So I thought I would check some of this out and along the way rebuild my Master-Detail with the GridView, DetailView and ModalPopup Controls and replace the ModalPopup with jQuery's ThickBox. I found it pretty interesting - read on to see how it went

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..

ToggleDebugCompilation fails trying to perform "an unauthorised operation"



We're having a problem with the Visual Studio 2008 RTW version of the web deployment projects on a colleagues machine. The project works fine if I run it on my machine, but when he tries to run it on his machine he gets:

<SNIP : Most output removed>
  Task "Exec"
    if exist ".\TempBuildDir\" rd /s /q ".\TempBuildDir\"
  Done executing task "Exec".
  Using "ToggleDebugCompilation" task from assembly "C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.Tasks.dll".
  Task "ToggleDebugCompilation"
    Updating Web.config <compilation> element debug attribute to 'True'.
    C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets(639,7): error : Attempted to perform an unauthorized operation.
    C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets(639,7): error MSB4018: The "ToggleDebugCompilation" task failed unexpectedly.
    C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets(639,7): error MSB4018: System.ArgumentNullException: Parameter "message" cannot be null.
    C:\Program Files\MSBuild\Microsoft\WebDeployment

ArrayList.ToArray fails!


In my app, I have code similar to the following:



               ArrayList alStartFrames = new ArrayList();
                byte[] abytTest = { 1, 2 };


                byte[] abytCombinedFrame = (byte[])alStartFrames.ToArray(typeof(byte));

            catch (Exception ex)

The call to ToArray always fails and the exception is caught even though I'm pretty sure alStartFrames is an array list of byte arrays. Anyone have any insight on why this is happening?! TIA

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. 

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