-1

The following code shows a part of my webpage.

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

In the code behind, I am using the following code.

btnPrevPage.Visible = false; btnNextPage.Visible = false; pageno.Visible = false; 

The problem is the buttons are getting hidden whereas when the third line to hide the page no, when I include that in the code, it throws the following error CS0103: The name 'pageno' does not exist in the current context. How do I fix this?

The full stack trace is as follows

 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 
1
  • 3
    you can't access any element in code without runat="server" in design Commented May 6, 2016 at 18:30

1 Answer 1

5

You need to add runat attribute in order to access the element in code behind

 <h3 ID = "pageno" runat="server">Page <%=PageNumber%> of <%=MaxPageNumber()%></h3> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.