内容控制必须达到顶级水平

时间:2013-08-23 18:04:16

标签: asp.net

我正在创建一个使用asp.net将信息发送到mysql服务器的网站。码。我遇到的问题是,当我调试代码并启动页面时,我收到一个错误:

    [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

我不知道为什么,我有这个错误。我试过制作一个新的网页和其他一切。 这是我的代码:

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;
    }
}
    }

我该如何解决这个问题?我弄清楚了。在此先感谢!

0 个答案:

没有答案