【发布时间】:2018-07-19 06:30:31
【问题描述】:
我已经在其他代码上完成了此操作,并且工作正常,但由于某种原因,在 VStudio 2017 中的一个新项目中,我无法从后面的 c# 代码中引用 asp/html 中的变量。然后,我使用其中的 about.aspx 开始了一个新的测试空白 asp web 项目,同样的事情参见下面的代码,我不知道为什么它不工作。我得到的“teststring”在当前上下文消息中不存在,但它确实存在。我在这里完全错过了什么吗?
ASP/HTML
<%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="TestApp.About" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: Title %>.</h2>
<h3>Your application description page.</h3>
<p>Use this area to provide additional information.</p>
<%=teststring %>
</asp:Content>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestApp
{
public partial class About : Page
{
public string teststring;
protected void Page_Load(object sender, EventArgs e)
{
teststring = "test";
}
}
}
【问题讨论】:
-
它会给您带来什么确切错误?是在抱怨
teststring吗?或者Title?您是否构建了解决方案? -
如果你断点 Page_Load 它真的命中了吗?您是否看到“使用此区域...”消息呈现在屏幕上?