Wednesday, November 12, 2014

How To Use UpdatePanel in Asp.net / How To Prevent PostBack Of Page Using Update Panel /How To Refresh The Particular Section Of The Page in Asp.net Using Update Panel



1 & 2 We will see the demo of the update panel
Try with this code
<form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="scriptmanager"></asp:ScriptManager>
    <div>
    <asp:Label ID="lbltime" runat="server"> </asp:Label>
    <asp:Timer ID="tmr" runat="server" Interval="1000" ontick="tmr_Tick"></asp:Timer>
    </div>
    </form>

  protected void tmr_Tick(object sender, EventArgs e)
    {
        lbltime.Text = DateTime.Now.ToString();
    }
Here we display the current time in the label and refreshing the page every time when you run this code you will see that page is refreshing automatically and whole control initialize again
So here we stop refreshing the page and only refresh the label without affecting the page

So we will use the update panel





3.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
//write here the code
    </ContentTemplate></asp:UpdatePanel>

Just doing this you can see that the page is not refreshing but only the control is refreshing itself

now run the page



No comments:

Post a Comment