可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
enter image description here
回答1:
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.
回答2:
You can use the navigation bar to switch context
is not an error. It just indicates that you can use a navigation bar to see your code in different context.
If you use a class in two projects (by using a linked file) you can use the bar to see code in ProjectA or ProjectB.
回答3:
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.