FileUpload in DetailsView fails with UpdatePanel

Last post 07-04-2008 7:18 PM by pinqguin. 11 replies.

Sort Posts:

  • FileUpload in DetailsView fails with UpdatePanel

    04-18-2007, 7:01 AM
    • Loading...
    • martinhn
    • Joined on 01-18-2006, 6:06 PM
    • Copenhagen, Denmark
    • Posts 114

    Hi

    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?

    OnUpdating

  • Re: FileUpload in DetailsView fails with UpdatePanel

    04-18-2007, 9:57 AM
    • Loading...
    • hankvbnet
    • Joined on 08-22-2005, 11:00 AM
    • The Netherlands
    • Posts 38

    An upload control cant work with an update panel. Because it has to force a postback to give back the posted file... you can force a postback of the upload control by using  :

                         <Triggers>
                           <asp:PostBackTrigger ControlID="Upload1" />
                         </Triggers>


    and force a postback for the upload control. Good Luck!

  • Re: FileUpload in DetailsView fails with UpdatePanel

    04-18-2007, 11:12 AM
    • Loading...
    • martinhn
    • Joined on 01-18-2006, 6:06 PM
    • Copenhagen, Denmark
    • Posts 114

    My FileUpoad control is placed inside a DetailsView.

     Therefore, you cannot reference the control by it's ID in the Triggers section.

    This throws an exception:

    A control with ID 'fi1' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: A control with ID 'fi1' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

    Is there another way to reference it?

  • Re: FileUpload in DetailsView fails with UpdatePanel

    05-02-2007, 9:25 PM
    • Loading...
    • vainternet
    • Joined on 02-07-2007, 12:42 PM
    • United Kingdom
    • Posts 12

    A quick way round this is to put a button outside of the datalist with visible set to false.

    when the page loads, the datalist buttons have not yet been rendered

  • Re: FileUpload in DetailsView fails with UpdatePanel

    05-02-2007, 11:51 PM

    See the online documentation which controls are not compatible with UpdatePanel

    http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: FileUpload in DetailsView fails with UpdatePanel

    05-15-2007, 6:23 AM
    • Loading...
    • arguiaren
    • Joined on 05-15-2007, 10:05 AM
    • Posts 1

    I am working in asp and I need  inserted an image in detailview.  I've used fileupload but read error. Help please. 

    Thanks

  • Re: FileUpload in DetailsView fails with UpdatePanel

    05-12-2008, 10:04 AM
    • Loading...
    • kylim
    • Joined on 05-17-2007, 5:46 AM
    • Posts 4

    I am facing the same problems....anyone could help!!!~

  • Re: FileUpload in DetailsView fails with UpdatePanel

    05-12-2008, 11:14 PM
  • Re: FileUpload in DetailsView fails with UpdatePanel

    06-17-2008, 10:57 AM

    I'm in the same boat and have been stuck on this issue for about 8 hours now.  If anyone has a solution please let me know.  I'm getting the PostBack trigger to work fine, but the FileName property on the FileUpload control is still empty.  By the way, here's how I got the trigger to work.  This is a usercontrol that contains a detailsview with a fileupload control inside of it.  The UpdatePanel is on the page.

     

    First, I added an OnItemCreated event to the details view.

    protected void dvNewAttachment_ItemCreated(object sender, EventArgs e)

    {

    Button btnSave = ((DetailsView)sender).FindControl("btnSave") as Button;

    if (btnSave != null)

    (this.Page as BasePage).RegisterPostbackTrigger(btnSave);

    }

     

    btnSave is just a Button control inside my DetailsView.  When it's clicked, that's when I save the file to the server.   BasePage is a custom class that subclasses the page class.  In there, I created a function  RegisterPostBackTrigger so I can call it from my usercontrols, or my page.  Here's the code for that function:

    public void RegisterPostbackTrigger(Control trigger)

    {

    ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(trigger);

    }

     

     

     

     

  • Re: FileUpload in DetailsView fails with UpdatePanel

    06-17-2008, 11:19 PM
    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: FileUpload in DetailsView fails with UpdatePanel

    06-18-2008, 1:20 PM

    I finally gave up.  I was able to get the FileUpload control working from a usercontrol inside a page that inherited a master page.  However, it just wouldn't seem to work from inside a detailsview.  It seems that adding the trigger in the ItemCreated event wasn't working. 

  • Re: FileUpload in DetailsView fails with UpdatePanel

    07-04-2008, 7:18 PM
    • Loading...
    • pinqguin
    • Joined on 03-16-2003, 1:46 AM
    • Posts 13

    I Solved it.

    As Hank adviced we should add the following:

    <Triggers>
       <asp:PostBackTrigger ControlID="fileUpload1" />
    </Triggers>
    This works perfect whenever the FileUpload control is a child control of the UpdatePanel's ContentTemplate.

    However when the FileUpload control is a child control of e.g. a DetailsViews, which is a child control of the UpdatePanel's ContentTemplate, we should not postback the FileUpload control but it's container.
    So in this case you would have to postback the DetailsView by using it's ID.

    <Triggers>
       <asp:PostBackTrigger ControlID="detailsView1" />
    </Triggers>
     
Page 1 of 1 (12 items)
Microsoft Communities
Page view counter