Powered by Blogger.

Friday, February 14, 2014

Ajax updatepanel example Asp.Net



Normally we use updatepanel for partial page refreshing, means the code within that panel will not postback. Microsoft provides AJAX which helps us in doing so.

For this our .aspx page should contain one ScriptManager and can contain more than one updatepanel control. The code that we put inside the updatepanel will not do postback on click event. UpdatePanel and ScriptManager are available in Toolbax under AJAX Extensions section.

Remember we need to put the scriptmanager control inside the form tag.

Below is the full HTML code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxUpdatePanel.aspx.cs"
    Inherits="AjaxUpdatePanel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Ajax updatepanel example in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button ID="btnAjaxNoRefresh" runat="server" Text="Click for no refresh !" OnClick="btnAjaxNoRefresh_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <div>
    </div>
    </form>
</body>

</html>





0 comments

Post a Comment