1

我正在制作一个使用 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

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

默认.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>

默认.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;
    }
}
    }

我该如何解决?我想不通。提前致谢!

4

0 回答 0