为什么我得到这个错误“The name'lblHelloWorld'在当前上下文中不存在”?我如何解决它?标签在当前上下文中不存在
<%@ 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文件并重新创建它,但没用。
如果你把标签放在UpdatePanel之外,它是否工作? – 2011-05-15 13:13:16
不,它仍然不起作用 – vatspoo 2011-05-15 13:16:11
接受的答案是否[这里](http://forums.asp.net/t/1006588.aspx/1?The+name+xxx+Does+Not+Exist+in+the+Current +上下文)也可以解决你的问题? – 2011-05-15 13:20:56