1

Im making a website that sends information to a mysql server, using asp.net. code. The problem Im having is that when i debug the code and launch the page, I get an error:

    [HttpException (0x80004005): Content controls have to be top-level controls in a         content page or a nested master page that references a master page.]
       System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context,         VirtualPath masterPageFile, IDictionary contentTemplateCollection) +9633920
       System.Web.UI.Page.get_Master() +54
       System.Web.UI.Page.ApplyMasterPage() +14
       System.Web.UI.Page.PerformPreInit() +45
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,         Boolean includeStagesAfterAsyncPoint) +335

Im not sure why, I have this error. I have tried making a new webpage and everything else. Here is my code:

Default.aspx

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default"%>  

    <form id="form1" runat="server">
    <div>
    <table width="300px" >
    <tr>
    <td>First Name</td>
    <td>
        <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
        </td>
    </tr>
        <tr>
    <td >Last Name</td>
    <td>
        <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
            </td>
    </tr>
        <tr>
    <td>User Name</td>
    <td>
        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            </td>
    </tr>
        <tr>
    <td>Password</td>
    <td>
        <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
            </td>
    </tr>
        <tr>
    <td>Email Address</td>
    <td>
        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            </td>
    </tr>
        <tr>
    <td>&nbsp;</td>
    <td>
        <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
            </td>
    </tr>
        <tr>
    <td>&nbsp;</td>
    <td>
        <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
            </td>
    </tr>
    </table>
    </div>
    </form>

Default.aspx.cs

    public partial class _Default : System.Web.UI.Page
    {
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSave_Click(object sender, EventArgs e)
{
    try
    {

        string cnnString = "Server=localhost;Port=3306;Database=ci_series;Uid=Bugalicious;Pwd=Comeonoutohtheweatheroutsideisweather1!";


        MySqlConnection connection = new MySqlConnection(cnnString);


        string cmdText = "INSERT INTO membership (first_name ,last_name ,username ,password ,";
        cmdText += "email_address)VALUES (first_name ,last_name ,username ,password ,email_address);";

        MySqlCommand cmd = new MySqlCommand(cmdText, connection);


        cmd.CommandType = CommandType.Text;
        cmd.Parameters.Add("?first_name", MySqlDbType.VarChar).Value = txtFirstName.Text;
        cmd.Parameters.Add("?last_name", MySqlDbType.VarChar).Value = txtLastName.Text;
        cmd.Parameters.Add("?username", MySqlDbType.VarChar).Value = txtUserName.Text;
        cmd.Parameters.Add("?password", MySqlDbType.VarChar).Value = txtPassword.Text;
        cmd.Parameters.Add("?email_address", MySqlDbType.VarChar).Value = txtEmail.Text;

        connection.Open();

        int result = cmd.ExecuteNonQuery();

        lblError.Text = "Data Saved";

    }
    catch (Exception ex)
    {
        lblError.Text = ex.Message;
    }
}
    }

How Do i Fix this? I cant figure it out. Thanks in Advance!

Alek Mieczkowski
  • 53
  • 1
  • 4
  • 7
  • Since you are using MasterPage your code should be inside something like `` – PiLHA Aug 23 '13 at 18:15
  • I suspect you are having the same trouble as this answered question -- http://stackoverflow.com/questions/835877/master-page-weirdness-content-controls-have-to-be-top-level-controls-in-a-con There are several mentioned possible source of the error you can check. – Gary Walker Aug 23 '13 at 18:26
  • @GaryWalker Yes that Was the error, I fixed it though by reformatting the tags that linked to the master page. – Alek Mieczkowski Aug 23 '13 at 18:43

0 Answers0