ASP.NET 网络表单:显示来自 c# 代码隐藏的值

ASP.NET web form: display value coming from c# code-behind

我正在使用 Visual Studio 2019,我正在创建一个网络表单。我的代码隐藏使用 sql 脚本从数据库中提取数据。我必须在 Web 表单中显示其中一些字段。

例如,project_description 是字段之一,在我的 .cs 文件中存储为 ProjDesc

在网络表单中,我有一个用于显示此字段的文本框:

<td class="auto-style29"><b>Project description</b></td>
<td class="auto-style5"><asp:TextBox Text="<insert variable>" ID="txtProjTitle" runat="server" Width="768px" Height="26px" ReadOnly ="true" Enabled="false" CssClass="auto-style16"></asp:TextBox></td>

它说 <insert variable> 的地方,我尝试使用变量名称 ProjDesc,但它被突出显示是因为 "it does not exist in the current context".

从我的 .aspx 文件中调用 ProjDesc 的正确方法是什么?它必须在 Text 属性下吗?

如果您使用的是 Web 表单,那么从 aspx 设置文本框文本的一种方法是在网页事件中,可能与触发 SQL 脚本的事件相同。

txtProjTitle.Text = ProjDesc