Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
i am using a timer to update the label at regular interval. i have written the simple code for it,but it is throwing an error that is Error 1: member names cannot be the same as their enclosing type

my asp code is
ASP.NET
<div>
            <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2000">
            </asp:Timer>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                </Triggers>
            </asp:UpdatePanel>
        </div>


and CodeBehind is
C#
protected void Page_Load(object sender, EventArgs e)
       {

       }

       protected void Timer1_Tick(object sender, EventArgs e)
       {
           Label1.Text = DateTime.Now.ToString();
       }


please help..
Posted

1 solution

Its working fine. Try to copy paste this in separate page;

XML
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="abc" runat="server"></asp:ScriptManager>
    <div>
        <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2000">
        </asp:Timer>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    </form>
</body>


C# code on CS file:
C#
protected void Timer1_Tick(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToString();
}
 
Share this answer
 

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