Managing user roles - is there a need for more than one LoginView in order to control more buttons

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 19:15:46

问题


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...

Do I need another LoginView or how can I do it?

Thanks


回答1:


I suspect that you are trying to access the controls directly from the code behind as you would naturally do.

e.g.

On the .aspx page

<asp:FileUpload id="fileUpload1" runat="server" />

In the code behind

 string fileName = fileUploadl.FileName;

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>

You can access the fileUpload1 control like this

 FileUpload fileUpload1 = (FileUpload) LoginView1.FindControl("fileUpload1");

Then you can access the fileUpload1 properties.



来源:https://stackoverflow.com/questions/8138139/managing-user-roles-is-there-a-need-for-more-than-one-loginview-in-order-to-co

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!