4
Digg me

If you form has asp:Fileupload control along with other controls like dropdownlist, calendar.. you will be facing standard problem of Fileupload control losing (the file) value when users click upload first and dropdown next.

This problem can be solved by using Updatepanel.  (AJAX)

Place all the controls inside updatepanel and place the FileUpload control and Upload button outside the panel.

Any autopostbacks will be handled by AJAX and Full postback will be handled by Upload button. 

Example:

<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>
   <ContentTemplate>
      <asp:DropDownList runat=”server” ID=”ddl” AutoPostBack=”true”>  </asp:DropDownList>
 <br/>
      <asp:Calendar ID=”calAsOfDate” runat=”server” DayNameFormat=”Shortest”> </asp:Calendar>
   </ContentTemplate>
</asp:UpdatePanel>

Fileupload placed outside the Panel

<asp:FileUpload Width=”600″ ID=”uldReport” runat=”server” /> <br/><br/>

<asp:button ID=”cmdCancel” runat=”server” UseSubmitBehavior=”false” CausesValidation=”false” Text=”Cancel” />&nbsp;&nbsp;

<asp:Button ID=”cmdUpload” runat=”server” Text=”Upload” OnClick=”cmdUpload_Click” />

Problem solved !!

5 com
1
Digg me

If you are using Update Panel and try to Export gridview contents to EXCEL or Word, your asp.net page will throw nasty error. “Sys.WebForms.PageRequestManagerParserErrorException”

Its because AJAX & Response.write don’t go together.  By calling Response.Write() directly you are bypassing the normal rendering mechanism of ASP.NET controls. The bits you write are going straight out to the client without further processing (well, mostly…). This means that UpdatePanel can’t encode the data in its special format.

There are couple of ways to solve this problem.

1. Place the Export Button outside of Update Panel.

2. By Pass the Export Button using <Triggers>

 </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID=”cmdExport” />
        </Triggers>

</asp:UpdatePanel>
if your Export button is part of UserControl then specify usercontrolid:buttonid

 </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID=”uscSelCtl:cmdExport” />
        </Triggers>
    </asp:UpdatePanel>

More Reading…

one

Archives

Tags