Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7196935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:52:25+00:00 2026-05-28T20:52:25+00:00

I am using VS2005 C# ASP.NET. I have a .aspx page with a script

  • 0

I am using VS2005 C# ASP.NET.

I have a .aspx page with a script for user user membership management.

However, when I tried to implement Masterpage to my .aspx page, I received an error which says

Content controls have to be top-level controls in a content page or a nested master page that references a master page.

I have correctly referenced to my masterpage and I do not know where have I gone wrong.

Need help in pointing out where have I gone wrong in my .aspx page.

Thank you


Below is my code for my .aspx and masterpage:

.ASPX:

<%@ Page Language="C#" MasterPageFile="~/MainPage.master"%>

<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" >
<script Runat="Server">

  string[] rolesArray;
  MembershipUserCollection users;
  string[] usersInRole;

  public void Page_Load()
  {
    Msg.Text = "";

    if (!IsPostBack)
    {
      // Bind roles to ListBox.

      rolesArray = Roles.GetAllRoles();
      RolesListBox.DataSource = rolesArray;
      RolesListBox.DataBind();

      // Bind users to ListBox.

      users = Membership.GetAllUsers();
      UsersListBox.DataSource = users;
      UsersListBox.DataBind();
    }

    if (RolesListBox.SelectedItem != null)
    {
      // Show users in role. Bind user list to GridView.

      usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
      UsersInRoleGrid.DataSource = usersInRole;
      UsersInRoleGrid.DataBind();
    }
  }


  public void AddUsers_OnClick(object sender, EventArgs args)
  {
    // Verify that a role is selected.

    if (RolesListBox.SelectedItem == null)
    {
      Msg.Text = "Please select a role.";
      return;
    }


    // Verify that at least one user is selected.

    if (UsersListBox.SelectedItem == null)
    {
      Msg.Text = "Please select one or more users.";
      return;
    }


    // Create list of users to be added to the selected role.

    string[] newusers = new string[UsersListBox.GetSelectedIndices().Length];

    for (int i = 0; i < newusers.Length; i++)
    {
      newusers[i] = UsersListBox.Items[UsersListBox.GetSelectedIndices()[i]].Value;
    }


    // Add the users to the selected role.

    try
    {
      Roles.AddUsersToRole(newusers, RolesListBox.SelectedItem.Value);

      // Re-bind users in role to GridView.

      usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
      UsersInRoleGrid.DataSource = usersInRole;
      UsersInRoleGrid.DataBind();

      Msg.Text = "User(s) added to role: " + RolesListBox.SelectedItem.Text;
      return;
    }
    catch (Exception e)
    {
      Msg.Text = e.Message;
    }
  }


  public void UsersInRoleGrid_RemoveFromRole(object sender, GridViewCommandEventArgs args)
  {
    // Get the selected user name to remove.

    int index = Convert.ToInt32(args.CommandArgument);

    string username = ((DataBoundLiteralControl)UsersInRoleGrid.Rows[index].Cells[0].Controls[0]).Text;


    // Remove the user from the selected role.

    try
    {
      Roles.RemoveUserFromRole(username, RolesListBox.SelectedItem.Value);
    }
    catch (Exception e)
    {
      Msg.Text = "An exception of type " + e.GetType().ToString() +
                 " was encountered removing the user from the role.";
    }


    // Re-bind users in role to GridView.

    usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
    UsersInRoleGrid.DataSource = usersInRole;
    UsersInRoleGrid.DataBind();

    Msg.Text = "User(s) removed from role: " + RolesListBox.SelectedItem.Text;
    return;
  }



</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>Role Membership</title>
</head>
<body>
  <form runat="server" id="PageForm">
    <font face="helvetica" size="6" color="#455c75"><strong>Role Membership</strong></font><font face="helvetica" size="5" color="#455c75"><strong> Management</strong></font><br /><asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
      <br />
    <table cellpadding="3" border="0">
      <tr>
        <td valign="top" style="width: 117px; height: 145px;">
          <font face="helvetica" size="3" color="#455c75"><strong>Roles:</strong></font></td>
        <td valign="top" style="height: 145px; width: 265px;">
          <asp:ListBox ID="RolesListBox" runat="server" Rows="8" AutoPostBack="true" /></td>
        <td valign="top" style="height: 145px">
          <font face="helvetica" size="3" color="#455c75"><strong>Users:</strong></font></td>
        <td valign="top" style="height: 145px">
          <asp:ListBox ID="UsersListBox" DataTextField="Username" Rows="8" SelectionMode="Multiple"
            runat="server" />
            <br />
          <asp:Button Text="Add User(s) to Role" ID="AddUsersButton" runat="server" OnClick="AddUsers_OnClick" /></td>
        <td valign="top" style="height: 145px">
          </td>
      </tr>
      <tr>
        <td valign="top" style="width: 117px">
          <font face="helvetica" size="3" color="#455c75"><strong>Users in Role:</strong></font></td>
        <td valign="top" style="width: 265px">
          <asp:GridView runat="server" CellPadding="4" ID="UsersInRoleGrid" AutoGenerateColumns="False"
            GridLines="Horizontal" OnRowCommand="UsersInRoleGrid_RemoveFromRole" ForeColor="#333333">
            <HeaderStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
            <Columns>
              <asp:TemplateField HeaderText="User Name" >
                <ItemTemplate>
                  <%# Container.DataItem.ToString() %>
                </ItemTemplate>
              </asp:TemplateField>
              <asp:ButtonField Text="Remove From Role" />
            </Columns>
              <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
              <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
              <EditRowStyle BackColor="#999999" />
              <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
              <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
              <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
          </asp:GridView>
        </td>
      </tr>
    </table>
  </form>
</body>
</html>
</asp:Content>

Masterpage:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MainPage.master.cs" Inherits="MainPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>RM</title>
    <link href="Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="wrapper">

        <form id="form1" runat="server">

            <div id="header" style="height: 2.7em">
                <span class="title">Role Management</span>
                <span class="breadcrumb">
    <asp:SiteMapPath ID="SiteMapPath1" runat="server">
    </asp:SiteMapPath>
</span>
            </div>

            <div id="content">
                <asp:contentplaceholder id="MainContent"
                 runat="server">
                  <!-- Page-specific content will go here... -->
                </asp:contentplaceholder>
                <br />
                &nbsp;</div>
            <div id="navigation" style="top: 4.19em; left: 0.51em;">
            <asp:Panel ID="Panel1" runat="server" Height="50px" Width="260px">
                <font size="2">You are logged in as </font>
                <asp:LoginName ID="LoginName1"  runat="server" Font-Bold="False" Font-Underline="False" ForeColor="RoyalBlue" Font-Italic="False" />
                <br />
                <asp:LinkButton ID="Logout" runat="server" Font-Bold="True" Font-Underline="True"
                    OnClick="Logout_Click" Font-Size="Smaller" ToolTip="Logout">Logout</asp:LinkButton></asp:Panel>
            <ul>
                    <li>
                        <asp:HyperLink runat="server" ID="lnkHome"
         NavigateUrl="/SoD/Common/Default.aspx">Home</asp:HyperLink>

        <asp:Repeater runat="server" ID="menu" DataSourceID="SiteMapDataSource1" EnableViewState="False">
    <ItemTemplate>
        <li>
            <asp:HyperLink ID="HyperLink1" runat="server"
             NavigateUrl='<%# Eval("Url") %>'>
             <%# Eval("Title") %></asp:HyperLink>

            <asp:Repeater ID="Repeater1" runat="server"
                DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
                <HeaderTemplate>
                    <ul>
                </HeaderTemplate>

                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="HyperLink2" runat="server"
                         NavigateUrl='<%# Eval("Url") %>'>
                         <%# Eval("Title") %></asp:HyperLink>
                    </li>
                </ItemTemplate>

                <FooterTemplate>
                    </ul>
                </FooterTemplate>
            </asp:Repeater>
        </li>
    </ItemTemplate>
</asp:Repeater>
                    </li>

    </ul>
</div>
    <asp:SiteMapDataSource ID="SiteMapDataSource1"
      runat="server" ShowStartingNode="false" />
      </form>
</div>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:52:26+00:00Added an answer on May 28, 2026 at 8:52 pm

    The <asp:Content> misses runat=”server”

    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server" >
    

    One more thing remove the following tags from the .aspx file
    <head> , <form>, <body>, and <html> because these tags are inherited from the Master Page

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2005 C# ASP.NET 2.0. I have used role management in the
I am using VS2005 C# ASP.NET. I have a webform which contains a list
I am using ASP.NET C# on VS2005. I have a GridView table with a
I am using C# ASP.NET on VS2005. I have a gridview table but it
I am using VS2005 ASP.NET 2.0. I have a web application which uses Active
I have a Windows 7 machine on which I am using VS2005. .Net 2.0
I am using Telerik asp.net mvc extensions. I have an issue that happens only
I am using VS2005 .NET 2.0 C#. I am currently managing my user roles
I have a small asp.net mvc app running on WIN2k3 and IIS6. I'm using
I am using VS2008, and ASP.NET 3.5 C# I have an array list that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.