问题
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