Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert record on button click with 4 tier

I am getting error

ASP.webform1_aspx' does not contain a definition for 'AddRecords' and no extension method 'AddRecords' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)

C#
 using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

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

        }


        protected void AddRecords(object sender, EventArgs e)
        {
            //Lets validate the page first
            if (!Page.IsValid)
                return;

            int intResult = 0;
            // Page is valid, lets go ahead and insert records
            // Instantiate BAL object
          
            PersonBAL pBAL = new PersonBAL();
            // Instantiate the object we have to deal with
            Person person = new Person();
            // set the properties of the object
            person.FirstName = NAME.Text;
            person.LastName = TextBox1.Text;
            person.Year = YEAR.Text;
            person.School = school_name.SelectedValue;
            person.City = TextBox2.Text;
            person.State = TextBox3.Text;
            person.Country = TextBox4.Text;
            person.E_mail = TextBox5.Text;
            person.Mobile = TextBox6.Text;

            //person.Age = Int32.Parse(txtAge.Text);

            try
            {
                intResult = pBAL.Insert(person);
                if (intResult > 0)
                     submit.Text = "New record inserted successfully.";
                else
                    submit.Text = "FirstName [" + TextBox6.Text + "] alredy exists, try another name";

            }
            catch (Exception ee)
            {
                submit.Text = ee.Message.ToString();
            }
            finally
            {
                person = null;
                pBAL = null;
            }
        }
    }
}



My Button Click code
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %>

<<body>
    <form id="form1" runat="server">
   
    <ajaxToolkit:ToolkitScriptManager  runat="server" ID="ScriptManager1" />
    <div id="wrap">
<div id="topbar">
  <ul>   
   <li class="current"><a href="#">Home</a></li>

    <li><a href="#">About Us</a></li>
    <li><a href="#">Contact us</a></li>
    <li><a href="#">Register Your Self</a></li>
  </ul>
  </div>
<div id="header">
<div id="sitename">
<h1 id="logo">SUEDP</h1>
</div>
<div id="shoutout"><img src="images/joinnow_shoutout.jpg" alt="Join Now! It's Free" width="168" height="126" /></div>
<div id="useractions">
<div id="headings"> 
<h2><img src="images/create_indi_usr.jpg" alt="Individual User" width="25" height="22" /> <a href="#">Any Time Help</a> </h2>   
<h2>Mr. Rajesh - +919785530723</h2>
<br />
<h2><img src="images/create_indi_usr.jpg" alt="Individual User" width="25" height="22" /> <a href="#">Any Time Help</a> </h2>   
<h2>Mr. Pankil - +919785530723</h2> <br />
 <h2><img src="images/create_indi_usr.jpg" alt="Individual User" width="25" height="22" /> <a href="#">Mail Us</a> </h2>   
<h2> info@suedp@suedp.dahodbazar.com</h2>
   
   <h1>
  <marquee>R & L pandya Celebrate 100 Year Sucess </marquee>
  </h1>
   </div>

</div>

<div id="content">
<div id="home_main">

<div id="search"> 

<ajaxToolkit:Accordion ID="MyAccordion"  runat="server" SelectedIndex="0"
            HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected"
            ContentCssClass="accordionContent" FadeTransitions="false" FramesPerSecond="40" 
            TransitionDuration="250" AutoSize="Fill" RequireOpenedPane="false" SuppressHeaderPostbacks="true">
           <Panes>
            <ajaxToolkit:AccordionPane ID="AccordionPane1"  runat="server">
                <Header><a href="" class="accordionLink">ENTER YOUR DETAILS</a></Header>

                <Content>

<table class="PANKIL">

<tr>
<td>NAME</td>
<td><asp:TextBox ID="NAME" CssClass="txtbx" runat="server"></asp:TextBox></td>

<td>
LAST NAME
</td>

<td>
<asp:TextBox ID="TextBox1" CssClass="txtbx" runat="server"></asp:TextBox>
</td>



<td>
PASS OUT YEAR
</td>
<td>
<asp:TextBox ID="YEAR" CssClass="txtbx" runat="server"></asp:TextBox>
</td>


</tr>





<tr>
<td>
SCHOOL NAME
</td>

<td>
<asp:DropDownList ID="school_name" runat="server">

<asp:ListItem>R.L.</asp:ListItem>
<asp:ListItem>M.Y.</asp:ListItem>
<asp:ListItem>GIRLS</asp:ListItem>


</asp:DropDownList>
</td>

<td>
CURRENT CITY
</td>
<td>

        <asp:TextBox ID="TextBox2" CssClass="txtbx" runat="server"></asp:TextBox>
</td>
<td>
CURRENT STATE
</td>

<td>

            <asp:TextBox ID="TextBox3" CssClass="txtbx" runat="server"></asp:TextBox>
</td>
</tr>
<tr>


<td>
CURRENT COUNTY
</td>
<td>

                <asp:TextBox ID="TextBox4" CssClass="txtbx" runat="server"></asp:TextBox>
</td>

<td>
E-MAIL
</td>
<td>

                    <asp:TextBox ID="TextBox5"  CssClass="txtbx" runat="server"></asp:TextBox>
</td>
<td>
MOBILE NUMBER
</td>

<td>

                        <asp:TextBox ID="TextBox6" CssClass="txtbx" runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="AddRecords" />
</td>
</tr>

</table>


</Content>

</ajaxToolkit:AccordionPane>


</Panes>

</ajaxToolkit:Accordion>

    </form>
</body>
Posted
Updated 2-Jan-14 22:26pm
v3
Comments
Thomas Daniels 2-Jan-14 13:16pm    
Could you provide your full ASP.NET code (not only the asp:Button)?
ZurdoDev 2-Jan-14 13:35pm    
I agree, we need to see the whole class. Your namespace may be off.
Pankil_Plus 3-Jan-14 4:27am    
I did update
ZurdoDev 3-Jan-14 7:20am    
I have a dumb suggestion. Comment out your AddRecords method. Then delete the button off the aspx page. Then go into Design View of your ASPX page and add the button again and then double-click on it so that .Net wires it up for you. It may be something in the designer file is actually off.
Pankil_Plus 5-Jan-14 14:18pm    
Thx for your reply I got my solution. I changed CodeFile="WebForm1.aspx.cs" & My problem is solved

1 solution

Seems like you have defined the AddRecords in one class file and your button click in another class (or aspx page). AddRecords method needs to be in the same class (or page). Suppose you have button in default.aspx page then AddRecords method needs to be defined in default.aspx.cs.
 
Share this answer
 
v2
Comments
Pankil_Plus 3-Jan-14 4:31am    
My Button is in webform1.aspx n Addrecords in webform1.aspx.cs file
gettgotcha 3-Jan-14 10:40am    
Then it shouldn't be a problem, check by creating sample project similarly and see you have the issue or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900