You can use the navigation bar to switch contex

匿名 (未验证) 提交于 2019-12-03 08:51:18

问题:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!