Shah
Shah

Reputation: 1654

The name 'placeholderName' does not exist in the current context

I have added placeholder to a page as below.

<tr > 
 <td >
  <asp:PlaceHolder ID="phMemberName" runat="server" >
  </asp:PlaceHolder>
 </td>
 <td>
 <asp:PlaceHolder ID="phMemberTextboxes" runat="server">
 </asp:PlaceHolder> 
</td>
 </tr>

I am adding controls(checkboxes) to it dynamically to it. It works fine but it throws an error if run in debug mode. What is the reason ?

The error is

The name 'phMemberName' does not exist in the current context

Upvotes: 0

Views: 2650

Answers (3)

Deepak Agrawal
Deepak Agrawal

Reputation: 121

You might be missing the aspx.designer.cs file. Since this file essentially glues the aspx markup controls to the CodeBehind page(aspx.cs), absence of this file can cause the CodeBehind page to not understand where the "placeholderName" placeholder control exists and hence the error "does not exist in current context".

Upvotes: 0

Shah
Shah

Reputation: 1654

The problem can be solved the issue using FindControl() like ,

PlaceHolder phMName = (PlaceHolder)form1.FindControl("ControlID");

check this

Upvotes: 1

Mikey Mouse
Mikey Mouse

Reputation: 3098

Is it possible you've made a typo? "The name 'placeholderName' does not exist in the current context" Should that not be "phMemberName"

Upvotes: 0

Related Questions