标签犯规在目前情况下存在 [英] Label doesnt exist in the current context

查看:163
本文介绍了标签犯规在目前情况下存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么M I收到此错误,在目前的情况下不存在名称'lblHelloWorld'?如何解决呢?

why m i getting this error "The name 'lblHelloWorld' does not exist in the current context"? How do i fix it?

<%@ Page Language="C#" AutoEventWireup="True" Inherits="_Default"      Codebehind="Default.aspx.cs" %>
<!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>Hello, world!</title>
</head>
<body>
<form id="form1" runat="server">
    <asp:ScriptManager ID="MainScriptManager" runat="server" />
    <asp:UpdatePanel ID="pnlHelloWorld" runat="server">
        <ContentTemplate>
            <asp:Label runat="server" ID="lblHelloWorld" Text="Click the button!" />
            <br /><br />
            <asp:Button runat="server" ID="btnHelloWorld" OnClick="btnHelloWorld_Click" Text="Update label!" />
        </ContentTemplate>
    </asp:UpdatePanel>
</form>


using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ajaxTesting
{
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnHelloWorld_Click(object sender, EventArgs e)
    {
        lblHelloWorld.Text = "Hello, world - this is a fresh message from ASP.NET AJAX! The time right now is: " + DateTime.Now.ToLongTimeString();
    }
}
}

我试过清洁和rebuliding;删除designer.cs文件,并重新创建它,但一点用也没有。

I tried cleaning and rebuliding; deleting the designer.cs file and recreating it but was of no use.

推荐答案

我觉得在你的 designer.cs file.Try问题手动添加此标签的参考在designer.cs文件。

I think the problem in your designer.cs file.Try to add a reference manually for this label in the designer.cs file.

编辑:

修订您的code后的问题是在命名空间

The problem after revision to your code is in the name space.

要解决您的问题:

这个替换您的行:

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

这篇关于标签犯规在目前情况下存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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