Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You can use the navigation bar to switch contex [duplicate]

Tags:

c#

asp.net

i'm working on ASP.net web site , in one of my forms i added HTML control , while using that control from the code behind file i got wiered error which i can't understand .

  <table style="width: 100%;" class="table-responsive">
            <tr>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                     <input id="UserName" runat="server" type="text" class="form-control" placeholder="Username" required="required"/>
                </td>
            </tr>
            <tr>

codeBehind file :

protected void Page_Load(object sender, EventArgs e)
{
   
}
public void signupData()
{
    string s = UserName.text;
}

error image

like image 707
Zaker typoir Avatar asked Mar 04 '17 18:03

Zaker typoir


2 Answers

This message can occur when two front end files reference a single back end class.

For example you could have two front end files called: signup.ascx and signupLight.ascx

These files then reference a shared back-end code file: signup.ascx.cs

The problem arises where you add a control to one of the front end files but not the other.

e.g. The UserName HtmlInputText control in your example could exist in signup.ascx but not signupLight.ascx so that when you reference it in signup.ascx.cs it is showing that one of the references is missing.

Another example could happen if you make a backup of the front end file by making a copy with a different filename but not adding the .exclude file extension. This will then interfere with trying to reference new front end controls in the back end, as the codefile tag is still pointing at the live code behind.

Unfortunately visual studio highlights this as needing to switch context and showing the names of two identical projects rather than the actual file where the reference originated, so you may have to do a search in your project for the backend filename to find all the active front end files where they are referenced.

like image 179
Radderz Avatar answered Sep 20 '22 00:09

Radderz


Visual Studio was giving me the same error. Made sure no front end files were referencing same back end files.

For me the fix was changing CodeFile to CodeBehind in the associated aspx.cs file. That resolved the error.

like image 24
William Avatar answered Sep 20 '22 00:09

William