【发布时间】:2015-07-31 12:28:20
【问题描述】:
我正在使用 C# ASP NET 制作网页。 我需要根据用户权限为 HTML 页面中的元素设置属性 Enabled 和 Visible。 它包括导航栏(菜单)、按钮、图表,一切......
我将从数据库中获取信息。我相信我会在数据库中需要这些信息:
1- 屏幕(字符串)
2- 元素名称(字符串)
3- 可见(布尔)
4- 启用
我可以有一个独特的功能来更改 OnLoadPage / OnInit 中的所有这些属性吗? 是否存在诸如“getElementByName()”之类的东西,它可以让任何类型的元素轻松更改其属性(可见/启用)?
我发现了一些问题,因为我也在使用 DevExpress,例如,我不能只使用 FindControl() 来查找 dx:aspnetGridView 中的所有元素。
例子:
public class ElementData
{
public string Path { get; set; }
public bool Visible { get; set; }
public bool Enabled { get; set; }
public void Adiciona(string Path, bool Visible, bool Enabled)
{
this.Path = Path;
this.Visible = Visible;
this.Enabled = Enabled;
}
}
public class UserMembershipElementsData
{
//User
public string UserName { get; set; }
//Membership
public string Password { get; set; }
public string Nome { get; set; }
public string Email { get; set; }
public List<ElementData> ElementsList { get; set; }
public UserMembershipElementsData(string Nome, string UserName, string Password, string Email)
{
this.UserName = UserName;
this.Password = Password;
this.Nome = Nome;
this.Email = Email;
this.ElementsList = new List<ElementData>();
}
}
public UserMembershipElementsData usr = new UserMembershipElementsData("Joao","admin","pass","jairo@tnah.com.br"); //declared as public
ElementData elm = new ElementData(); //just part of the code
elm.Adiciona("btnAdiciona", true, false); //Add, Visible, Disabled
usr.ElementsList.Add(elm);
protected void grdDados_CustomButtonInitialize(object sender, ASPxGridViewCustomButtonEventArgs e)
{
if (e.VisibleIndex == -1) return;
foreach (ElementData elm in usr.ElementsList)
{
if (e.ButtonID == elm.Path)
{
e.Visible = DefaultBoolean.True; ///Permission I couldnt use elm.Visible
e.Enabled = elm.Enabled; //Permission
break;
}
}
}
正如你所看到的,我只是在测试,我没有输入页面的名称。 如果你给我一条路,我会很高兴的。谢谢。
【问题讨论】:
-
我尝试使用 DataBinding,但问题是 dx:asp GridView 不允许 DataBinding。
标签: c# asp.net properties getelementsbytagname