Telerik 控件中的控件无法从 .cs 文件访问
我在我的 c# asp.net 项目中使用 telerik 控件。我正在尝试从 .cs 文件禁用 telerik 导航菜单中的 div。例如:
if (Emp_Role == "1" || Emp_Role == "5")
{
DivLeave.Visible = true;
}
我尝试运行该项目,但收到此错误:
CS0103:当前上下文中不存在名称“DivLeave”
这是 aspx 代码的示例
<telerik:RadMenu runat="server" ID="RadMenu1" Skin="Sitefinity" OnClientItemOpened="itemOpened"
Width="670px" Height="26px" EnableShadows="true">
<Items>
<telerik:RadMenuItem Text="Expenses" PostBack="false">
<Items>
<telerik:RadMenuItem CssClass="Stores" Width="640px">
<ItemTemplate>
<div id="DivLeave" class="Wrapper">
<h3>
Expense Management</h3>
</div>
有人可以帮忙吗?如果我将 div 放在 telerik 控件之外,它就可以正常工作。这太令人沮丧了!
亲切的问候,
R
I am using telerik controls in my c# asp.net project. I am trying to disable a div in a telerik navigation menu from the .cs file. For example:
if (Emp_Role == "1" || Emp_Role == "5")
{
DivLeave.Visible = true;
}
I try run the project I get this error:
CS0103: The name 'DivLeave' does not exist in the current context
Here is an example of the aspx code
<telerik:RadMenu runat="server" ID="RadMenu1" Skin="Sitefinity" OnClientItemOpened="itemOpened"
Width="670px" Height="26px" EnableShadows="true">
<Items>
<telerik:RadMenuItem Text="Expenses" PostBack="false">
<Items>
<telerik:RadMenuItem CssClass="Stores" Width="640px">
<ItemTemplate>
<div id="DivLeave" class="Wrapper">
<h3>
Expense Management</h3>
</div>
Can anyone help with this? If I place the div outside the telerik control it works fine. This is so frustrating!
Kind regards,
R
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您必须使用 asp.net 控件(或至少是在服务器中运行的控件)才能从后面的代码访问它。例如。
其次,要获得 Telerik 控件内的控件,您需要一些特殊代码。在您的示例中,您可以执行以下操作:
要了解更多信息:
访问模板内的控件
First, you have to use a asp.net control ( or at least a control that runs in server ) to be able to access it from code behind. For example.
Second, to get a control inside a Telerik control you need som special code. In your example, you can do something like this:
To learn more:
Accessing Controls Inside Templates
在客户端执行此操作也可以工作,并且您不必使 div 成为服务器端。
使用 jQuery,您可以:
假设这些 div 元素最初使用 "display: none;" CSS 规则隐藏。
Doing it client side will also work and you won't have to make the div become server side.
Using jQuery you can have:
This assumes those div elements are initially hidden using "display: none;" CSS rule.