Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi , I am having two update panels -panel1 and panel2 and a timer to update panel1 but timer updates both the update panel..

Here is the code..

C#
protected void Page_Load(object sender, EventArgs e)
    {
        lbl_Date.Text = DateTime.Now.ToString();
        lbl_Date0.Text = DateTime.Now.ToString();
        lbl_Date1.Text = DateTime.Now.ToString();
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        lbl_Date0.Text = DateTime.Now.ToString();
    }






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

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
            <div>
                <asp:Label ID="lbl_Date" runat="server" Text="Label"> </asp:Label>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
            </div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <br />
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            &nbsp;<asp:Button ID="Button1" runat="server" Text="Button" />


            <br />
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:Timer ID="Timer1" runat="server" Interval="1000">
                    </asp:Timer>
                    <br />
                    <asp:Label ID="lbl_Date0" runat="server" Text="Label"> </asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
            <br />
            <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                <ContentTemplate>
                    <br />
                    <asp:Label ID="lbl_Date1" runat="server" Text="Label"> </asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>


    <br />
    </form>
</body>
</html>
Posted

1 solution

Put UpdateMode="Conditional" in both the Update panels next to their ID's defined.

Refer, details here: MSDN: UpdatePanel.UpdateMode Property [^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900