错误1'计时器':成员名称不能与其封闭类型相同 [英] Error 1 'timer': member names cannot be the same as their enclosing type

查看:118
本文介绍了错误1'计时器':成员名称不能与其封闭类型相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用计时器定期更新标签。我已经为它编写了简单的代码,但它抛出的错误是错误1:成员名称不能与其封闭类型相同



我的asp代码是

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

<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>





和CodeBehind是



and CodeBehind is

protected void Page_Load(object sender, EventArgs e)
       {

       }

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





请帮助..



please help..

推荐答案

工作正常。尝试将其粘贴在单独的页面中;



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

<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>





CS文件上的C#代码:



C# code on CS file:

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


这篇关于错误1'计时器':成员名称不能与其封闭类型相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆