Take the 2-minute tour ×

The Scenario:
I have an ASP.Net webpage which I intend to use for letting the user(not the real users, but content manager basically) insert and edit the records in a table using a FormView. This FormView is inside an UpdatePanel, as I'm also using cascading dropdownlists to let the user select some values.

Now, this FormView also contains 4 FileUpload controls, and as you might know that these fileupload controls require a full postback since most browsers do not let Javascript access the disk. So, this problem would have been solved by doing something like:

           <asp:PostBackTrigger ControlID="InsertButton" />
           <asp:PostBackTrigger ControlID="UpdateButton" />

Edit: Forgot to add that the fileuploading takes place in the OnUpdating and OnInserting events of the SqlDataSource.

The Problem:
Since the InsertButton and the UpdateButton reside inside the Formview, I cannot directly access their ID's through markup. And MSDN says that:

Programmatically adding PostBackTrigger controls is not supported.

Please suggest some solution to make this work. Any insight on the matter is highly appreciated. Thanks.

P.S.- A workable solution for me was to set the UpdatePanel's PostBackTrigger as the whole FormView itself:

           <asp:PostBackTrigger ControlID="FormView1" />

But now due to a bit of change in requirements, this solution(if you call it a solution) is not acceptable.

share|improve this question

2 Answers 2

Have you given a though about using Iframe for doing the postback ? something like:

<iframe name="uploader" id=uploader 
          src="uploaderSender.aspx?AllowedExtension=<%= AllowedExtension %>&StoringPath=<%= StoringPath %>&StoringFileName=<%= StoringFileName %>&OldFileName=<%= OldFileName %>&MaximumSize=<%= MaximumSize %>"
         width="450" height="50" frameborder=0  scrolling=no >

with uploaderSender.aspx like :

<form action="UploaderReceiver.aspx" method="post"  enctype="multipart/form-data">
 <input type="file" name="file" id="file"  onchange="document.getElementById('IsFileUploading').style.visibility = 'visible'; document.forms[0].submit()"/>

    <span id="IsFileUploading" style="visibility: hidden">
        <asp:Image ID="Image1" runat="server" ImageUrl="~/immagini/Ajax-loader.gif" />

and UploaderReceiver.aspx like :

protected void Page_Load(object sender, EventArgs e)

            //if there is one file to process
            if (Request.Files.Count > 0)
                //create the folder if it does'nt exists and returns the local path to get it
                string StoringPathToBeSaved = StoringPath.GetFolderPath();

                // append the name of the file to upload to the path.
                            StoringPathToBeSaved = StoringPathToBeSaved + StoringFileName + Extension;



this is just bits of code just for you to figure out if you would be interested in this way of dealing with the upload, I can give you more if you want after.

see you, and good luck with your code,

share|improve this answer
Thanks for your input sir, but actually I currently am sort of a beginner with ASP.Net itself, and have not an iota of an idea about IFrames, and although it would work as you say, but I'm afraid right now I just have to finish this task at hand(and a few others too) in a couple of hours and I guess it would take me some time to learn IFrames and also implement them into my project. Anyways, thanks for your help. +1 to you :) –  Anchit Aug 24 '10 at 11:53
up vote 1 down vote accepted

Yay!! Finally got it to work!

Here's How:

Well contrary to what MSDN says, we can in fact add PostBack Triggers Programmatically. Not necessarily to the UpdatePanel, but to the ScriptManager.

After hours of playing around, here's what worked:

We are not able to access controls inside a FormView, untill the template has been rendered, so we can only add postback triggers after the formview's OnDataBound Event.

protected void FormView1_DataBound(object sender, EventArgs e)
        if (FormView1.CurrentMode == FormViewMode.Edit)
            LinkButton lb = (LinkButton)FormView1.FindControl("UpdateButton");

        //Similarily you can put register the Insert LinkButton as well.

And now, if your UpdatePanel causes ConditionalUpdate, you can do something like this to make it work:

The Markup:

            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" OnClick="Cause_PostBack"CommandName="Update">Update</asp:LinkButton>


//call this function as the OnClick Event Handler for the Controls you want to register as
protected void Cause_PostBack()

Otherwise, if your situation allows it(as mine does), just set the UpdatePanel's UpdateMode="Always"

share|improve this answer

Your Answer


