关于ASP前端页面中“上下文找不到名称xxx"的解决办法(vs的bug?)

来源:互联网 发布:淘宝绣花针 编辑:程序博客网 时间:2024/06/07 01:49
简介:今天在asp中编写音乐播放器时,前端页面需要调用后端页面中的一个String属性。使用<%=xx%>,明明在后台存在的属性,但是在编写工程中就是会报错 ”在上下文中找不到名称xx“,网上看了很多办法,就是无法解决。后来我强行运行,居然能运行得了。在后面的编程过程中也不再报这样的错误,具体示例代码如下;
namespace Light{    public partial class WebForm1 : System.Web.UI.Page    {        public String a = "a ";        protected void Page_Load(object sender, EventArgs e)        {        }    }}

WebForm1.aspx.cs(后台代码)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Light.WebForm1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <title></title></head><body>    <form id="form1" runat="server">    <div>        <%=a %>    </div>    </form></body></html>

WebForm1.aspx(前台代码)

编写时错误,但是能运行。


此外还有其他的原因导致该错误,见他人博客吧。

0 0