1,105,578 Community Members

ClickSave is not a member of ASP.default_aspx

Member Avatar
Malymieczek
Light Poster
35 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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;
                }
            }
        }
    }
Member Avatar
JorgeM
IT Addict
6,421 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 963 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
0
 

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.

Member Avatar
Malymieczek
Light Poster
35 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
JorgeM
IT Addict
6,421 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 963 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
0
 

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

Attachments
Member Avatar
Malymieczek
Light Poster
35 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
JorgeM
IT Addict
6,421 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 963 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
0
 

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.

Member Avatar
Malymieczek
Light Poster
35 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
Malymieczek
Light Poster
35 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Attachments
Member Avatar
JorgeM
IT Addict
6,421 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 963 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
0
 

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.

Member Avatar
Malymieczek
Light Poster
35 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
ss125
Posting Whiz in Training
200 posts since Jul 2013
Reputation Points: 18 [?]
Q&As Helped to Solve: 22 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article