管理用户角色-是否需要多个LoginView来控制更多按钮 [英] Managing user roles - is there a need for more than one LoginView in order to control more buttons
问题描述
我创建了一个LoginView,以使一个按钮对普通用户(即非管理员)隐藏.效果很好,但是当我尝试添加另外两个按钮-FileUploadControl和Upload按钮时,出现错误消息FileUpload1不存在.它肯定存在,我不明白为什么会抱怨...
I created a LoginView in order to keep one button hidden from normal users, i.e not admins. Works great but when I tried to add two more buttons - FileUploadControl and Upload button, I get an error that FileUpload1 does not exist. It definitely exists and I don't get why it complains...
我需要另一个LoginView还是该怎么做?
Do I need another LoginView or how can I do it?
谢谢
推荐答案
我怀疑您试图像自然地那样直接从后面的代码访问控件.
I suspect that you are trying to access the controls directly from the code behind as you would naturally do.
例如
在.aspx页面上
<asp:FileUpload id="fileUpload1" runat="server" />
在后面的代码中
string fileName = fileUploadl.FileName;
但是,当控件位于 LoginView
中时,不能直接访问控件.您需要执行以下操作.因此,如果您拥有这样的控件.
However, you cannot access controls directly when they are within the LoginView
. You need to do the following. So if you had the control like this.
<asp:LoginView id="LoginView1" runat="server">
<AnonymousTemplate>
<asp:FileUpload ID="fileUpload1" runat="server" />
</AnonymousTemplate>
</asp:LoginView>
您可以像这样访问fileUpload1控件
You can access the fileUpload1 control like this
FileUpload fileUpload1 = (FileUpload) LoginView1.FindControl("fileUpload1");
然后,您可以访问 fileUpload1
属性.
Then you can access the fileUpload1
properties.
这篇关于管理用户角色-是否需要多个LoginView来控制更多按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!