我正在尝试访问自定义用户控件的 html 片段中的公共布尔值。这是我的代码隐藏的一部分:
public partial class ToDoList : System.Web.UI.UserControl
{
public bool ShowAddNewButton { get; set; }
public bool CreateMode { get;set;}
protected void Page_Load(object sender, EventArgs e)
{
}
}
这是我的html:
<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="ToDoList.ascx.cs" Inherits="ToDoList" %>
<div id="leftNav">
<asp:HiddenField ID="hfNAVItems" runat="server" />
<asp:HiddenField ID="hfRequestID" runat="server" />
<asp:HiddenField runat="server" ID="hdnAllowDragDrop" />
<div class='nav-header'>
<div>
My To-Do List</div>
</div>
<ul id="mainNav" class="nav-item-list">
<li class="nav-item" id="firstNavContainer">
<div>
<span class="nav-item-todos">
<asp:Label Text="" runat="server" ID="lblfirstSectionHeader" /></span>
<% if(ShowAddNewButton)
{ %>
<asp:Button ID="Button1" runat="server" Text="Add New" CssClass="navaddnewrequest todo-button"
OnClick="btnNewToDo_Click" />
<%} %>
</div>
<ul id="todosNav">
<% if (CreateMode)
{ %>
<li class="SelectedNavHeader">New Todo</li>
<% } %>
<asp:Repeater runat="server" ID="rptToDoNavItems">
<ItemTemplate>
<li class="ToDoSelectedNavGroup" runat="server" id="liToDoNavGroupCont">
<asp:Literal runat="server" ID="lblToDoNavGroupDisplay" /></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ul>
<ul id="lineItemNav">
<li class="darkgradient header">My Lists</li>
</ul>
</div>
我收到以下错误:
当前上下文中不存在名称“ShowAddNewButton”当前上下文中不存在
名称“CreateMode”
在这个问题上挠头……似乎很简单。很高兴得知我遗漏了一些完全明显的东西。
提前致谢