c# - ASP.NET 网络表单 : display value coming from c# code-behind

标签 c# asp.net webforms code-behind

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

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

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

<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 , 但这是突出显示的,因为“它在当前上下文中不存在”。

正确的记忆方式是什么ProjDesc从我的 .aspx 文件?它必须在 Text 下吗?属性?

最佳答案

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

txtProjTitle.Text = ProjDesc

关于c# - ASP.NET 网络表单 : display value coming from c# code-behind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58454198/

相关文章:

css - 在 Asp :Button 中使用 Font Awesome 备忘单的最佳方式

html - Firefox 4 必需的输入表单红色边框/轮廓

asp.net - 为什么应用程序也会命中本地 ADFS?

c# - Reflector 将不再免费。还有其他选择吗?

c# - 正则表达式匹配具有不同分辨率后缀的剧集标题

c# - Asp.Net 弹出错误信息

asp.net - 将 Angular2 应用程序包含到 Asp.Net Webforms 页面

c# - 如何在 UWP 应用程序中通过 log4net 配置日志记录

c# - 当我在 C# 中使用今天的日期时,为什么时间会变成 0000

c# - ASP.NET MVC 中基于不同角色的条件只读/可编辑属性