以下代码显示了我网页的一部分。
<h3 ID = "pageno">Page <%=PageNumber%> of <%=MaxPageNumber()%></h3>
<asp:Button ID="btnPrevPage" runat="server" Text="Prev Page" Class="Shape1" OnClick="onPrevPageClick" />
<asp:Button ID="btnNextPage" runat="server" Text="Next Page" Class="Shape1" OnClick="onNextPageClick" />
在后面的代码中,我使用以下代码。
btnPrevPage.Visible = false;
btnNextPage.Visible = false;
pageno.Visible = false;
问题是按钮被隐藏了,而当第三行隐藏页面时没有,当我在代码中包含它时,它会抛出以下错误 CS0103:名称&#39; pageno&#39;在当前上下文中不存在。我该如何解决这个问题?
完整堆栈跟踪如下
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'pageno' does not exist in the current context
Source Error:
Line 37: BlogEntries1.SetData(myDataSet, "");
Line 38:
Line 39: pageno.Visible = false;
Line 40: btnPrevPage.Visible = false;
Line 41: btnNextPage.Visible = false;
Source File: c:\Inetpub\wwwroot\casts-alt\blog\blog2.aspx.cs Line: 39
答案 0 :(得分:5)
您需要添加runat
属性才能访问
<h3 ID = "pageno" runat="server">Page <%=PageNumber%> of <%=MaxPageNumber()%></h3>