HI All, im working on a project that uses asp.net to send information to a mssql server. The problem im running into is that when i try to debug the page, I get: 'ClickSave' is not a member of 'ASP.default_aspx'.
How Do I fix this??
Heres My html code(default.aspx):

 <html>

    <head></head>
    <body>
        <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="ClickSave" />
                </td>
        </tr>
            <tr>
        <td>&nbsp;</td>
        <td>
            <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
                </td>
        </tr>
        </table>
        </div>
        </form>
    </body>
    </html> 

ASP code(default.aspx.cs):

 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using MySql.Data.MySqlClient;
    using System.Data;

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

            }

            protected void ClickSave(object sender, EventArgs e)
            {
                try
                {

                    string cnnString = "Server=localhost;Port=3306;Database=ci_series;Uid=xxxxx;Pwd=xxxxx";


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

Dani AI

Generated

The error "ClickSave is not a member of 'ASP.default_aspx'" means the compiled page class that ASP.NET created doesn't have the event handler or the control declaration the markup expects. was right that the page declaration matters and was right to point you at the designer file — the usual causes are a mismatch between the .aspx directive and the code‑behind class (namespace/class name or CodeFile/CodeBehind), a missing or out‑of‑date designer file, or a control/method name mismatch.

A short checklist to work through (do these in order):

  1. Confirm project type (Web Site vs Web Application). Use the correct Page directive style for that type and make the Inherits value match the code‑behind class including namespace (for example, if your code declares namespace Mysqlpart1 and class _Default, the Inherits must reference that fully qualified name).
  2. Verify markup: the Button must have runat="server" and its ID must exactly match the designer/code‑behind names; the OnClick value must match the method name (case matters).
  3. Open Default.aspx.designer.cs and make sure protected fields exist for btnSave and the textboxes. If they’re missing or wrong, regenerate the designer (Web Application: right‑click the .aspx → Convert to Web Application; Web Site: saving the page / rebuild usually regenerates it).
  4. Clean the solution, delete temporary build folders if needed, then Rebuild. Also ensure .cs files have Build Action = Compile and there are no duplicate class names.

Extra gotchas: adding the wrong Page directive can produce a flood of syntax errors (that’s usually the CodeFile/CodeBehind or Inherits mismatch). Make sure your ClickSave method has the standard signature (object sender, EventArgs e) and isn’t accidentally inside a different class or namespace.

Finally, your INSERT statement needs proper parameter placeholders and you shouldn’t store plaintext passwords. Example (correct the VALUES to use parameter placeholders):

INSERT INTO membership (first_name,last_name,username,password,email_address)
VALUES (?first_name,?last_name,?username,?password,?email_address);

Also wrap connections/commands in using blocks and store passwords hashed (bcrypt/Argon2) rather than plain text.

Recommended Answers

All 10 Replies

Your default.aspx sample above appears to be missing the page declerations which should be the first line of code. Something like...

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Other than that, I tested your code, with the exception of the database related code, and everything worked as expected.

I tried adding that line to the top of the page, but now im just getting around 140 syntax errors on that one line of code... Do I just ignore this?

Sounds like a typo or your inherits is not matching up...

The easiest way to deal with this is just create a new page using Visual Studio, Add New Item, Web Form, enable "place code in seperate file".

Then add in your clicksave subroutine and any Using statements that you need like "using MySql.Data.MySqlClient;"

This is exactly what I did to test your code. your form comes up with no probelm.

8a9026039b49c0ab03834c9ebe4c9a2b

I have no Idea how to do that. Where do I find "place code in seperate file"?

When you right click a folder for example in solution explorer, you will see an option to add a new item. Once you select web form at the bottom right you have two options... The master page file and separate code file checkboxes.

I dont have any Add option when I right click a folder/file/website/blank space in Solution Explorer. Im using VS 2010, maybe thats why?

Ok so what I did was I made a new site, and copy and pasted the table and c# code in, as well as added the mysql.data reference. I compiled it and.... Got this page when i ran the debug: 2e9275f96c3b7f3e763c707fe2c90f4f

So you have a different problem now. Did you decide to include a master page with the new site?

It's hard for me to know exactly what the problem is because I suspect that your current code is no longer exactly as what you originally posted.

If you are in the process of learning, I'd create a new site build your page first, test it, then add in your code behind code a section at a time, testing as you go.

The problem is, that I did that, and I still have the same error.

I think this may fix the issue

open the [formname].designer.cs

and check whether there is a code like below

protected global::System.Web.UI.WebControls.Button clicksave;

If not add the code...

Hope this helps you..

Have a happie coding...:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.