C# ASP.NET按复选框分配角色
我正在使用VS2005 C# 我有一个用户列表和两个复选框。复选框分别指示C# ASP.NET按复选框分配角色,c#,asp.net,visual-studio,C#,Asp.net,Visual Studio,我正在使用VS2005 C# 我有一个用户列表和两个复选框。复选框分别指示管理员和用户。选择用户后,将根据分配给该用户的角色选中相应的复选框 现在我正试图通过选中/取消选中复选框来添加/删除所选用户的角色,但我遇到了一些问题。页面将重新加载一段时间,并将复选框状态重置为原始状态,角色不会更改 下面是我的代码片段: 任何人都可以帮我发现错误?将复选框按钮放在更新面板中 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Con
管理员
和用户
。选择用户后,将根据分配给该用户的角色选中相应的复选框
现在我正试图通过选中/取消选中复选框来添加/删除所选用户的角色,但我遇到了一些问题。页面将重新加载一段时间,并将复选框状态重置为原始状态,角色不会更改
下面是我的代码片段:
任何人都可以帮我发现错误?将复选框按钮放在更新面板中
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="adminCB" runat="server" Text="Administrator" OnCheckedChanged="Admin_CC" AutoPostBack="true"/><br />
<asp:CheckBox ID="userCB" runat="server" Text="User" OnCheckedChanged="User_CC" AutoPostBack="true"/>
</ContentTemplate>
</asp:UpdatePanel>
刚刚编辑了我的评论。您可能需要在apsx页面顶部安装一个scriptmanager。我使用的是VS2005,我认为不支持updatepanel。无论如何谢谢你,我想你应该有它。该控件在ajax扩展下。
protected void Admin_CC(Object sender, EventArgs e)
{
if (adminCB.Checked)
{
Roles.AddUserToRole(UsersListBox3.SelectedItem.Value, "Administrator");
// Re-bind users in role to GridView.
usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
UsersInRoleGrid.DataSource = usersInRole;
UsersInRoleGrid.DataBind();
}
if (adminCB==null)
{
Roles.RemoveUserFromRole(UsersListBox3.SelectedItem.Value, "Administrator");
// Re-bind users in role to GridView.
usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
UsersInRoleGrid.DataSource = usersInRole;
UsersInRoleGrid.DataBind();
}
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="adminCB" runat="server" Text="Administrator" OnCheckedChanged="Admin_CC" AutoPostBack="true"/><br />
<asp:CheckBox ID="userCB" runat="server" Text="User" OnCheckedChanged="User_CC" AutoPostBack="true"/>
</ContentTemplate>
</asp:UpdatePanel>