Saturday, March 24, 2012

my page is slower with ajax than without it. Help!

Hi,

I am using ajax extensions 1.0 and ajaxcontroltoolkit in my web pages. I only use the calendarextender and the tabcontainer of the toolkit.

On the other hand I use an updatepanel that contains my controls and grid in the page.

When I test the web page with ajax, it is slower than when I test it without the scriptmanager and updatepanel, etc.

I have in the web config:

<compilationdebug="false">

<scriptResourceHandlerenableCompression="true"enableCaching="true"/>

Is it common that ajax is slower than the normal page?

What can I do to make ajax faster?

thanks in advance,

Daniel.

Take a look at this post:http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/

That's not to say you should never use an UpdatePanel, but you need to understand how it works and use it appropriately. Without knowing more about your particular page's design, it's hard to give more specific advice.


Ok, thank you for the information.

I have a question:

Is it bad to have only one updatepanel that surrounds all the controls in the web page? or it is better to have several updatepanels in the web page?

Is not there any other way to put faster the perfomance in ajax to have it the same speed that the web page without ajax?

thanks a lot,

Daniel.


If your page has more than just a few controls on it, I would definitely recommend using multiple UpdatePanels. You can't avoid the ViewState and page reinstantiation, but you can at least cut down on how much HTML is returned and how much work the PageRequestManager has to put into parsing and updating that content. Make sure to use an UpdateMode of Conditional when working with multiple UpdatePanels.

If you want faster performance, try to use web methods or page methods as I describe in my post. When using light weight mechanisms like that, you can both achieve huge performance gains and reduce server load.


Hi,

I am still having the problem: my page is slower with ajax, than without it.

I have an updatepanel for the page. I tried to put the updatepanel only for the gridview but everything was the same, so I think my problem is not that I'm using only one updatepanel for the whole page.

Can you see my code below and help me, please?

I have several panels, objectdatasource, one gridview, code in HTML.

thanks a lot,

Daniel.

<%@.PageLanguage="C#"MasterPageFile="~/_plantillas/plantillamain.master"AutoEventWireup="true"CodeFile="clientesabc.aspx.cs"Inherits="clientes_clientesabc"Title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="conditional">

<ContentTemplate>

<asp:PanelID="pnlExterior"runat="server"Width="100%">

HTML

<asp:PanelID="pnlDatos"runat="server"Width="100%"Visible="false">

HTML

</asp:Panel>

<asp:PanelID="pnlResumenVentasCompras"runat="server"Width="100%"Visible="false">

HTML

</asp:Panel>

<asp:LabelID="lblTituloGrid"runat="server"CssClass="LabelRealizado"></asp:Label>

<asp:LinkButtonID="lbtQuitarFiltro"runat="server"OnClick="lbtQuitarFiltro_Click"CausesValidation="False">Quitar Filtro</asp:LinkButton><br/>

<asp:GridViewID="gvw1"runat="server"Width="100%"AllowPaging="True"AllowSorting="True"AutoGenerateColumns="False"DataKeyNames="intIDCodigoCliente_fl"DataSourceID="odsClientes"GridLines="Horizontal"CaptionAlign="Left"CssClass="CeldaFondoMasClara"BorderColor="Silver"BorderWidth="1px"OnPageIndexChanged="gvw1_PageIndexChanged"OnPageIndexChanging="gvw1_PageIndexChanging"OnRowDataBound="gvw1_RowDataBound"OnSelectedIndexChanged="gvw1_SelectedIndexChanged"OnSorted="gvw1_Sorted"OnSorting="gvw1_Sorting"PageSize="20">

<Columns>

<asp:TemplateFieldShowHeader="False">

<ItemTemplate>

<asp:ImageButtonID="ibtEliminar"runat="server"CausesValidation="false"CommandName="Delete"ImageUrl="~/_archivos/iconos/gridEliminar.gif"ToolTip="Eliminar"BorderWidth="0"ImageAlign="AbsMiddle"/>

</ItemTemplate>

<ItemStyleWidth="20px"/>

</asp:TemplateField>

<asp:CommandFieldButtonType="Image"ShowSelectButton="True"SelectImageUrl="~/_archivos/iconos/gridSeleccionar.gif"SelectText="Seleccionar">

<ItemStyleWidth="20px"/>

</asp:CommandField>

<asp:TemplateFieldHeaderText="# Cliente"SortExpression="intIDCodigoCliente_fl">

<ItemTemplate>

<asp:LabelID="lblNumeroCliente"runat="server"Text='<%# Bind("intIDCodigoCliente_fl") %>'></asp:Label>

</ItemTemplate>

<ControlStyleCssClass="TextBoxNormal"/>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Sucursal"SortExpression="vchNombreSucursal_fl">

<ItemTemplate>

<asp:LabelID="lblSucursal"runat="server"Text='<%# Bind("vchNombreSucursal_fl") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Razón Social"SortExpression="vchRazonSocial_fl">

<ItemTemplate>

<asp:LabelID="lblRazonSocial"runat="server"Text='<%# Bind("vchRazonSocial_fl") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="RFC"SortExpression="vchRFC_fl">

<ItemTemplate>

<asp:LabelID="lblRFC"runat="server"Text='<%# Bind("vchRFC_fl") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Contacto">

<ItemTemplate>

<spanclass="LabelSubrayado">Telef</span>:<asp:LabelID="lblTelefono1"runat="server"Text='<%# Bind("vchTelefono1_fl") %>'></asp:Label> ,<asp:LabelID="lblTelefono2"runat="server"Text='<%# Eval("vchTelefono2_fl") %>'></asp:Label><br/>

<spanclass="LabelSubrayado">Email</span>:<asp:HyperLinkID="hlkEmail"Text='<%# Bind("vchEmail_fl") %>'NavigateUrl='<%# Correo(Eval("vchEmail_fl")) %>'CssClass="EnlaceSinNegrita"runat="server"></asp:HyperLink><br/>

<spanclass="LabelSubrayado">Contacto</span>:<asp:LabelID="lblContacto"runat="server"Text='<%# Bind("vchContacto_fl") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Persona">

<ItemTemplate>

<asp:LabelID="lblPersona"runat="server"Text='<%# TipoPersona(Eval("bitPersonaFisica_fl"))%>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderImageUrl="~/_archivos/iconos/gridusuarioActivar.gif"HeaderText="Activo">

<ItemTemplate>

<asp:CheckBoxID="ckbActivo"runat="server"Checked='<%# ValorBoolean(Eval("IsApproved")) %>'Enabled="false"/>

</ItemTemplate>

<HeaderStyleHorizontalAlign="Center"/>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Tipo de Venta">

<ItemTemplate>

<asp:LabelID="lblTipoVenta"runat="server"Text='<%# Bind("ClienteEstatusVenta")%>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldShowHeader="False"HeaderText="CAMPOS OCULTOS">

<ItemTemplate>

<asp:LabelID="lblNombreCliente"runat="server"Text='<%# Bind("vchNombreCliente_fl") %>'></asp:Label>

<asp:LabelID="lblCalle"runat="server"Text='<%# Bind("vchCalle_fl") %>'></asp:Label>

<asp:LabelID="lblNumExterior"runat="server"Text='<%# Bind("vchNumeroExterior_fl") %>'></asp:Label>

<asp:LabelID="lblNumInterior"runat="server"Text='<%# Bind("vchNumeroInterior_fl") %>'></asp:Label>

<asp:LabelID="lblEntreCalle1"runat="server"Text='<%# Bind("vchEntreCalle1_fl") %>'></asp:Label>

<asp:LabelID="lblEntreCalle2"runat="server"Text='<%# Bind("vchEntreCalle2_fl") %>'></asp:Label>

<asp:LabelID="lblColonia"runat="server"Text='<%# Bind("vchColonia_fl") %>'></asp:Label>

<asp:LabelID="lblEstado"runat="server"Text='<%# Bind("Estado") %>'></asp:Label>

<asp:LabelID="lblMunicipio"runat="server"Text='<%# Bind("Municipio") %>'></asp:Label>

<asp:LabelID="lblPoblacion"runat="server"Text='<%# Bind("vchPoblacion_fl") %>'></asp:Label>

<asp:LabelID="lblFax"runat="server"Text='<%# Bind("vchFax_fl") %>'></asp:Label>

<asp:LabelID="lblCP"runat="server"Text='<%# Bind("vchCodigoPostal_fl") %>'></asp:Label>

<asp:LabelID="lblPrecioLista"runat="server"Text='<%# Bind("sinPrecioListaFacturar_fl") %>'></asp:Label>

<asp:LabelID="lblDescuento"runat="server"Text='<%# Bind("monDescuento_fl") %>'></asp:Label>

<asp:LabelID="lblDiasPlazo"runat="server"Text='<%# Bind("sinDiasPlazoPago_fl") %>'></asp:Label>

<asp:LabelID="lblDescuentoProntoPago"runat="server"Text='<%# Bind("monDescuentoProntoPago_fl") %>'></asp:Label>

<asp:LabelID="lblComision"runat="server"Text='<%# Bind("monComisionVenta_fl") %>'></asp:Label>

<asp:LabelID="lblLimiteCredito"runat="server"Text='<%# Bind("monLimiteCredito_fl") %>'></asp:Label>

<asp:LabelID="lblIDClienteEstatusVenta"runat="server"Text='<%# Bind("sinIDClienteEstatusVenta_fl") %>'></asp:Label>

<asp:LabelID="lblIDClienteMedioEmbarque"runat="server"Text='<%# Bind("sinIDClienteMedioEmbarque_fl") %>'></asp:Label>

<asp:LabelID="lblUserId"runat="server"Text='<%# Bind("UserId") %>'></asp:Label>

<asp:CheckBoxID="ckbCambiaPassword"runat="server"Checked='<%# ValorBoolean(Eval("bitCambiaPassword_fl")) %>'/>

<asp:CheckBoxID="ckbRevLu"runat="server"Checked='<%# ValorBoolean(Eval("bitRevisionLunes_fl")) %>'/>

<asp:CheckBoxID="ckbRevMa"runat="server"Checked='<%# ValorBoolean(Eval("bitRevisionMartes_fl")) %>'/>

<asp:CheckBoxID="ckbRevMi"runat="server"Checked='<%# ValorBoolean(Eval("bitRevisionMiercoles_fl")) %>'/>

<asp:CheckBoxID="ckbRevJu"runat="server"Checked='<%# ValorBoolean(Eval("bitRevisionJueves_fl")) %>'/>

<asp:CheckBoxID="ckbRevVi"runat="server"Checked='<%# ValorBoolean(Eval("bitRevisionViernes_fl")) %>'/>

<asp:CheckBoxID="ckbRevSa"runat="server"Checked='<%# ValorBoolean(Eval("bitRevisionSabado_fl")) %>'/>

<asp:CheckBoxID="ckbPagLu"runat="server"Checked='<%# ValorBoolean(Eval("bitPagoLunes_fl")) %>'/>

<asp:CheckBoxID="ckbPagMa"runat="server"Checked='<%# ValorBoolean(Eval("bitPagoMartes_fl")) %>'/>

<asp:CheckBoxID="ckbPagMi"runat="server"Checked='<%# ValorBoolean(Eval("bitPagoMiercoles_fl")) %>'/>

<asp:CheckBoxID="ckbPagJu"runat="server"Checked='<%# ValorBoolean(Eval("bitPagoJueves_fl")) %>'/>

<asp:CheckBoxID="ckbPagVi"runat="server"Checked='<%# ValorBoolean(Eval("bitPagoViernes_fl")) %>'/>

<asp:CheckBoxID="ckbPagSa"runat="server"Checked='<%# ValorBoolean(Eval("bitPagoSabado_fl")) %>'/>

<asp:LabelID="lblmonVenta01"runat="server"Text='<%# Bind("monVenta01_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta02"runat="server"Text='<%# Bind("monVenta02_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta03"runat="server"Text='<%# Bind("monVenta03_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta04"runat="server"Text='<%# Bind("monVenta04_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta05"runat="server"Text='<%# Bind("monVenta05_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta06"runat="server"Text='<%# Bind("monVenta06_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta07"runat="server"Text='<%# Bind("monVenta07_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta08"runat="server"Text='<%# Bind("monVenta08_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta09"runat="server"Text='<%# Bind("monVenta09_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta10"runat="server"Text='<%# Bind("monVenta10_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta11"runat="server"Text='<%# Bind("monVenta11_fl") %>'></asp:Label>

<asp:LabelID="lblmonVenta12"runat="server"Text='<%# Bind("monVenta12_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado01"runat="server"Text='<%# Bind("monPagado01_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado02"runat="server"Text='<%# Bind("monPagado02_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado03"runat="server"Text='<%# Bind("monPagado03_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado04"runat="server"Text='<%# Bind("monPagado04_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado05"runat="server"Text='<%# Bind("monPagado05_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado06"runat="server"Text='<%# Bind("monPagado06_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado07"runat="server"Text='<%# Bind("monPagado07_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado08"runat="server"Text='<%# Bind("monPagado08_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado09"runat="server"Text='<%# Bind("monPagado09_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado10"runat="server"Text='<%# Bind("monPagado10_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado11"runat="server"Text='<%# Bind("monPagado11_fl") %>'></asp:Label>

<asp:LabelID="lblmonPagado12"runat="server"Text='<%# Bind("monPagado12_fl") %>'></asp:Label>

</ItemTemplate>

<ControlStyleCssClass="oculto"/>

<ItemStyleCssClass="oculto"/>

<HeaderStyleCssClass="oculto"/>

<FooterStyleCssClass="oculto"/>

</asp:TemplateField>

</Columns>

<SelectedRowStyleCssClass="CeldaFilaBrillante"/>

<PagerSettingsMode="NumericFirstLast"/>

<PagerStyleCssClass="GridPaging"/>

<HeaderStyleHorizontalAlign="Left"CssClass="CeldaFondoClara"/>

</asp:GridView>

8 ObjectDataSource

</asp:Panel>

</ContentTemplate>

</asp:UpdatePanel>

</asp:Content>


have you tried to evaluate why the page is slow by using fiddler? This could give you an indication of where the slow down is occuring and also ensure that everything is being cached where it can be.

Also, if you have a large viewstate, you may want to look at overriding the PageStatePersister property and save your viewstate to session using theSessionPageStatePersister object.

No comments:

Post a Comment