Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

c# / Executing a Stored Procedure from an asp.net page to update a SQL 2005 Table

HI there,

c# / Executing a Stored Procedure from an asp.net page.

the asp.net form page is as follows:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateNewLeadSourceProvider.aspx.cs" Inherits="FORTUNE.LeadSourceProviders.CreateNewLeadSourceProvider" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
    {

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>F.O.R.T.U.N.E. - Lead Source Providers</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <span style="font-family: Arial"><strong><span style="font-size: 14pt">Create a New Lead Source Provider<br />
            <br />
            <br />
        </span></strong>
            Step 1 :: Define New Lead Source Provider Profile<br />
            <br />
            <br />
        </span>
        <asp:Label ID="Label_LeadSourceProviderName" runat="server" Font-Names="Arial" Font-Size="Small"
            Height="20px" Text="Lead Source Provider Name" Width="200px"></asp:Label><span style="font-family: Arial">
            </span>
        <asp:TextBox ID="TextBox_LeadSourceProviderName" runat="server" Font-Names="Arial"
            Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><span style="font-family: Arial"><br />
                <br />
            </span>
        <asp:Label ID="Label_CompanyRegisteredName" runat="server" Font-Names="Arial" Font-Size="Small"
            Height="20px" Text="Company Registered Name" Width="200px"></asp:Label><span style="font-family: Arial">
            </span>
        <asp:TextBox ID="TextBox_CompanyRegisteredName" runat="server" Font-Names="Arial"
            Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><span style="font-family: Arial"><br />
                <asp:Label ID="Label_CompanyRegistrationNumber" runat="server" Font-Names="Arial"
                    Font-Size="Small" Height="20px" Text="Company Registration Number" Width="200px"></asp:Label><span
                        style="font-family: Arial"> </span>
                <asp:TextBox ID="TextBox_CompanyRegistrationNumber" runat="server" Font-Names="Arial"
                    Font-Size="Small" MaxLength="50"></asp:TextBox><br />
                <span style="font-family: Arial">
                    <br />
                    <asp:Label ID="Label1" runat="server" Font-Names="Arial" Font-Size="Small" Height="20px"
                        Text="VAT Registered" Width="200px"></asp:Label><span style="font-family: Arial">
                            <asp:RadioButton ID="RadioButton_Yes" runat="server" Font-Names="Arial" Font-Size="Small"
                                GroupName="RadioButton_ValueAddTaxRegistrationRef" Text="Yes" />&nbsp; <span style="font-size: 10pt"></span>
                            <asp:RadioButton ID="RadioButton_No" runat="server" Checked="True" Font-Names="Arial"
                                Font-Size="Small" GroupName="RadioButton_ValueAddTaxRegistrationRef" Text="No" /></span><br />
                        <asp:Label ID="Label_ValueAddTaxRegistration" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="VAT Registration Number" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_ValueAddTaxRegistration" runat="server" Font-Names="Arial"
                            Font-Size="Small" MaxLength="50"></asp:TextBox><span style="font-family: Arial"><br />
                            </span>
                        <br />
                        <asp:Label ID="Label_Switchboard" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Switchboard" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_Switchboard" runat="server" Font-Names="Arial" Font-Size="Small" MaxLength="50"></asp:TextBox><br />
                        <asp:Label ID="Label_LandlineFax" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Landline Fax" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_LandlineFax" runat="server" Font-Names="Arial" Font-Size="Small" MaxLength="50"></asp:TextBox><span
                            style="font-family: Arial"><br />
                        </span>
                        <br />
                        <asp:Label ID="Label_WebsiteURL" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Website URL" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_WebsiteURL" runat="server" Font-Names="Arial" Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><br />
                        <asp:Label ID="Label_EmailAddress" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Email Address" Width="200px"></asp:Label>
                        <asp:TextBox ID="TextBox_EmailAddress" runat="server" Font-Names="Arial" Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><br />
                    <br />
                    </span>
                <asp:Label ID="Label_ComplianceConfirmed" runat="server" Font-Names="Arial" Font-Size="Small"
                    Height="20px" Text="Compliance Confirmed" Width="200px"></asp:Label><asp:CheckBox
                        ID="CheckBox_ComplianceConfirmed" runat="server" Font-Names="Arial" Font-Size="Small" /><br />
                <br />
                <br />
            </span>
        <asp:Button ID="Button_CreateNewLeadSourceProvider" runat="server" Text="Create New Lead Source Provider"
            Width="235px" OnClick="Button_CreateNewLeadSourceProvider_Click" />
        &nbsp;&nbsp;
        <asp:Label ID="Label_SubmissionStatus" runat="server" Font-Size="8pt" ForeColor="Red"></asp:Label><br />
        <br />
        <br />
        <span style="font-size: 10pt; font-family: Arial"><strong>Step 1 - Define New Lead Source
            Provider Profile</strong><br />
            Step 2 -
            <asp:HyperLink ID="HyperLink_CreateAddress" runat="server" NavigateUrl="~/LeadSourceProviders/CreateNewLeadSourceProviderAddress.aspx">Create Address</asp:HyperLink><br />
            Step 3 -
            <asp:HyperLink ID="HyperLink_CreateContact" runat="server" NavigateUrl="~/LeadSourceProviders/CreateNewLeadSourceProviderContact.aspx">Create Contact</asp:HyperLink><br />
            Step 4 -
            <asp:HyperLink ID="HyperLink_CreateProduct" runat="server" NavigateUrl="~/LeadSourceProviders/CreateNewLeadSourceProviderProduct.aspx">Create Product</asp:HyperLink></span></div>
    </form>
</body>
</html>



the Stored Procedure as follows:

ALTER PROCEDURE BackOffice.InsertNewLeadSourceProvider

@LeadSourceProviderName      nvarchar(50),
@CompanyRegisteredName      nvarchar(50),
@CompanyRegistrationNumber      nvarchar(50),
@ValueAddTaxRegistered      bit,
@ValueAddTaxRegistrationRef      nvarchar(50),
@Switchboard            nvarchar(50),
@LandlineFax            nvarchar(50),
@WebsiteURL            nvarchar(50),
@EmailAddress            nvarchar(50),
@ComplianceConfirmed            bit

AS
BEGIN

INSERT LeadSourceProviders (LeadSourceProviderName,
      CompanyRegisteredName,                         CompanyRegistrationNumber,                         ValueAddTaxRegistered,                         ValueAddTaxRegistrationRef,
      Switchboard,
      LandlineFax,
      WebsiteURL,
      EmailAddress,
      ComplianceConfirmed)
                                          
VALUES (@LeadSourceProviderName,
                @CompanyRegisteredName,
                @CompanyRegistrationNumber,
                @ValueAddTaxRegistered,
                @ValueAddTaxRegistrationRef,
                @Switchboard,
                @LandlineFax,
                @WebsiteURL,
                @EmailAddress,
                @ComplianceConfirmed)
END


the asp.net form .cs code (i.e. code activated from button submit) as follows:

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 FORTUNE.LeadSourceProviders
{
    public partial class CreateNewLeadSourceProvider : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
        {
            SqlDataSource FORTUNESQLDataSource = new SqlDataSource();
            Label_SubmissionStatus.Text = null;

            FORTUNESQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["FORTUNEConnectionString"].ToString();

            FORTUNESQLDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
            FORTUNESQLDataSource.InsertCommand = "BackOffice.InsertNewLeadSourceProvider";

            FORTUNESQLDataSource.InsertParameters.Add("@LeadSourceProviderName", "Test 1");
            FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegisteredName", "Test 1");
            FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegistrationNumber", "1234567890");
            FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistered", "TRUE");
            FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistrationRef", "1234567890");
            FORTUNESQLDataSource.InsertParameters.Add("@Switchboard", "1234");
            FORTUNESQLDataSource.InsertParameters.Add("@LandlineFax", "1234");
            FORTUNESQLDataSource.InsertParameters.Add("@WebsiteURL", "test.com");
            FORTUNESQLDataSource.InsertParameters.Add("@EmailAddress", "post@test.com");
            FORTUNESQLDataSource.InsertParameters.Add("@ComplianceConfirmed", "TRUE");

            //FORTUNESQLDataSource.InsertParameters.Add("@LeadSourceProviderName",        TextBox_LeadSourceProviderName.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegisteredName",         TextBox_CompanyRegisteredName.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegistrationNumber",     TextBox_CompanyRegistrationNumber.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistered",         TextBox_ValueAddTaxRegistered.Bit);
            //FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistrationRef",    TextBox_ValueAddTaxRegistrationRef.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@Switchboard",                   TextBox_Switchboard.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@LandlineFax",                   TextBox_LandlineFax.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@WebsiteURL",                    TextBox_WebsiteURL.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@EmailAddress",                  TextBox_EmailAddress.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@ComplianceConfirmed",           TextBox_ComplianceConfirmed.Bit);

            //FORTUNESQLDataSource.InsertParameters.Add("ActiveMemberStatus",         CheckBox_ActiveMemberStatus.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("DateTimeStamp",              DateTime.Now.ToString());
            //FORTUNESQLDataSource.InsertParameters.Add("DataEntryUser",              "ADMIN");
            //FORTUNESQLDataSource.InsertParameters.Add("UniqueSessionID",            Session.SessionID);
            //FORTUNESQLDataSource.InsertParameters.Add("UserIPAddress",              Request.UserHostAddress.ToString());

            int RowsAffected = 0;

            try
            {
                RowsAffected = FORTUNESQLDataSource.Insert();
            }
            catch (Exception)
            {
                SQL_FailureHandler();
            }
            finally
            {
                Label_SubmissionStatus.Text = "[ Comitted to Database OK ]";

                FORTUNESQLDataSource = null;
            }

            TextBox_LeadSourceProviderName.Text     = null;
            TextBox_CompanyRegisteredName.Text      = null;
            TextBox_CompanyRegistrationNumber.Text  = null;
            TextBox_ValueAddTaxRegistration.Text    = null;
            TextBox_SwitchboardNumber.Text          = null;
            TextBox_LandlineFax.Text                = null;
            TextBox_WebsiteURL.Text                 = null;
            TextBox_EmailAddress.Text               = null;
            //CheckBox_ActiveMemberStatus.Text        = "FALSE";
       
        }

        private void SQL_FailureHandler()
        {
            // TODO SQL Failure Handler needs to be scripted

            Label_SubmissionStatus.Text = "[ Commit to Database FAILURE ]";
        }
    }
}


The SQL 2005 database table has the same variables names and variable types as described in the Stored Procedure, and all set to allowing 'null' entries for the time being.  The only two extra columns in the database table are:  LeadSourceProvider_ID, int (auto increment) and DateTimeStamp (getDate()) -- bot set to non-null entry status.



the commented out code (on the form c# scripting portion) are the actual field values I would like to pass -- but have 'hard coded' the values in the meantime, trying to isolate where the error is.

The above scripts provide the data entry form ok, the Stored Procedure works fine when executed directly via SQL server (when adding manually the default values when submitting via SQL Server).

The problem is .... that when submitting the form button, the Stored Procedure does not appear to be activated correctly (or passing variable across etc) -- the effect is that nothing is updated to the database table accordingly.

Hopefully I have diligent enough with providing enough supporting evidence to work with.

Your time and efforts with this request for assistance is much apprieated.

Kind regards,
-andrew.
SOLUTION
Avatar of RaisinJ
RaisinJ

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amillyard

ASKER

Have deleted the above scripting as requested and the stored proecedure is firing up as indicated.

I am certain that this has fixed the initial question (many thanks).

There is now the following error message:


Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   FORTUNE.LeadSourceProviders.CreateNewLeadSourceProvider.Button_CreateNewLeadSourceProvider_Click(Object sender, EventArgs e) in C:\Documents and Settings\Andrew Millyard\My Documents\Visual Studio 2005\Projects\FORTUNE\FORTUNE\LeadSourceProviders\CreateNewLeadSourceProvider.aspx.cs:35
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42


this is related to something else needs looking at?  (do I need to submit this as a seperate question or can apend to this existing thread?)

I am working remotely on the site/sql server -- yet I am seeing a local c:/ drive reference above in the error.

Many thanks,
-andrew.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK -- you are referring to the following method:

protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
        {
            SqlDataSource FORTUNESQLDataSource = new SqlDataSource();
            Label_SubmissionStatus.Text = null;

            FORTUNESQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["FORTUNEConnectionString"].ToString();

            FORTUNESQLDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
            FORTUNESQLDataSource.InsertCommand = "BackOffice.InsertNewLeadSourceProvider";

            FORTUNESQLDataSource.InsertParameters.Add("@LeadSourceProviderName", "Test 1");
            FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegisteredName", "Test 1");
            FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegistrationNumber", "1234567890");
            FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistered", "TRUE");
            FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistrationRef", "1234567890");
            FORTUNESQLDataSource.InsertParameters.Add("@Switchboard", "1234");
            FORTUNESQLDataSource.InsertParameters.Add("@LandlineFax", "1234");
            FORTUNESQLDataSource.InsertParameters.Add("@WebsiteURL", "test.com");
            FORTUNESQLDataSource.InsertParameters.Add("@EmailAddress", "post@test.com");
            FORTUNESQLDataSource.InsertParameters.Add("@ComplianceConfirmed", "TRUE");

            //FORTUNESQLDataSource.InsertParameters.Add("@LeadSourceProviderName",        TextBox_LeadSourceProviderName.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegisteredName",         TextBox_CompanyRegisteredName.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegistrationNumber",     TextBox_CompanyRegistrationNumber.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistered",         TextBox_ValueAddTaxRegistered.Bit);
            //FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistrationRef",    TextBox_ValueAddTaxRegistrationRef.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@Switchboard",                   TextBox_Switchboard.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@LandlineFax",                   TextBox_LandlineFax.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@WebsiteURL",                    TextBox_WebsiteURL.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@EmailAddress",                  TextBox_EmailAddress.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@ComplianceConfirmed",           TextBox_ComplianceConfirmed.Bit);

            //FORTUNESQLDataSource.InsertParameters.Add("ActiveMemberStatus",             CheckBox_ActiveMemberStatus.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("DateTimeStamp",                  DateTime.Now.ToString());
            //FORTUNESQLDataSource.InsertParameters.Add("DataEntryUser",                  "ADMIN");
            //FORTUNESQLDataSource.InsertParameters.Add("UniqueSessionID",                Session.SessionID);
            //FORTUNESQLDataSource.InsertParameters.Add("UserIPAddress",                  Request.UserHostAddress.ToString());

            int RowsAffected = 0;

            try
            {
                RowsAffected = FORTUNESQLDataSource.Insert();
            }
            catch (Exception)
            {
                SQL_FailureHandler();
            }
            finally
            {
                Label_SubmissionStatus.Text = "[ Comitted to Database OK ]";

                FORTUNESQLDataSource = null;
            }

            TextBox_LeadSourceProviderName.Text     = null;
            TextBox_CompanyRegisteredName.Text      = null;
            TextBox_CompanyRegistrationNumber.Text  = null;
            TextBox_ValueAddTaxRegistration.Text    = null;
            TextBox_SwitchboardNumber.Text          = null;
            TextBox_LandlineFax.Text                = null;
            TextBox_WebsiteURL.Text                 = null;
            TextBox_EmailAddress.Text               = null;
            //CheckBox_ActiveMemberStatus.Text        = "FALSE";
       
        }



asking if I can debug locally -- i.e. via the Studio environment (step through) ?   assuming this is so -- am in the process of doing that now.

-andrew.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tried to start the debug -- eventually the following Studio error message as follows:

Unable to start debugging on the web server.  The format of the specified network name is invalid.

-andrew.
mmm...interesting...

when I double-clicked on the submit button as indicated -- there is another script now added into the .aspx form page (i.e. not where the original button click prodcedure sits in the .cs file) as follows:

<script runat="server">

    protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
    {

    }
</script>

-andrew.
Avatar of RaisinJ
RaisinJ

Do you have the Visual Studio's Project open locally on your machine?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
as a result, when clicking the submit button via the form .aspx page, obviously nothing is now firing up (as an empty container) ... yet the other .cs code (button submit) is still available as code.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
confirming that Visual Studio is open locally (desktop) -- connecting to web server / sql server remotely
confirming the @page header as follows:   (the .cs file name is exactly the same as indicated below)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateNewLeadSourceProvider.aspx.cs" Inherits="FORTUNE.LeadSourceProviders.CreateNewLeadSourceProvider" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
    {

    }
</script>
Removed the string as requested.

"Go to the Designer of the application and in the properties toolbox, with the button selected, check the Events associated to the button. Delete the stting "Button_CreateNewLeadSourceProvider_Click" in the Click  cell. Once deleted refresh the view and double click the button. Move your code to inside this new event handler."

Also, removed the previously inserted auto script in the .aspx and .cs page (as by double-clicking we are creating a new instance of the procedure).

Then saved .aspx page, refreshed (close pages and reopened .aspx).  Double-clicked on the submit button, and again the procedure as above is inserted into the .aspx page.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just checking this double-clicking on submit button and inserting empty procedure container into .cs automatically -- is affecting on all other .aspx pages as well at the moment.  so, its consistent across the project.

is there a global setting that has been changed perhaps inadvertantly?
Are they code-behind pages in the same directory as the aspx pages on the web server?  If you website is not published but instead the pages and are just copied to the web server directory, the .cs files need to be there as well.
Changed the button script as requested above.

The following build error message with that .aspx page as follows:


'ASP.leadsourceproviders_createnewleadsourceprovider_aspx' does not contain a definition for MyButtonClickHandler
Checking on the @page error log -- the following message is also appearing:

Warning      1      
Attribute 'Codebehind' in the @ Page directive is no longer supported. Convert this page to the new code-behind model by opening the Web site (project) containing the page in Visual Web Developer.

-- not sure how to change this?  is this what's affecting the @page issue perhaps?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Which version of .NET are you using, did you recently upgrade?  In your @Page directive try changing "CodeBehind" to "CodeFile" as the @Page directive attributes have changed, this if of course if you have a new version of the .net framework.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes...success !  ... created a new .aspx form page, added a button, double-clicked and the procedure container appeared in the .cs file fine (as normally would expect).

not sure why this .cs association seems to have just broken itself on the existing files..but, putting that to one-side, will rebuild the .apsx page in question (as a fresh page) and make sure the advise above is adhered too to confirm all is well (i.e. answer original question!, as we got a little side tracked) -- do apprieate your attentiveness to this enquiry.

Obviously, I am looking to see if the error message will arise again (when processing the stored procedure) -- when trying to debug earlier, was when the .cs linking seem to got disturbed etc.

Is it possible to debud remotely?  (as failed earlier)
ok -- just got your @page update ... will do this first
applied the @page change -- the button double-clicking is now working (via .cs file) and the other MyButtonClickHandler(object sender, EventArgs e) is not visible ok and functional.
no errors or warning are appearing now :-) when compiling page/site
ok -- I think we are making progress...

so far as, the page compiles, displays ok, and I can press submit (via the web browser) without getting any processing error messages etc.

the form indicates that the database table has been updated (checking rows affected status), but when I check the actual database table in question - there is no updating going on.
I am getting this warning now:

Warning      1      The type 'FORTUNE.LeadSourceProviders.CreateNewLeadSourceProvider' in 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\staging.one-trust.co.uk\b2c1e47d\c616ae6e\App_Web_createnewleadsourceprovider.aspx.905d605a.lx9trvbk.0.cs' conflicts with the imported type 'FORTUNE.LeadSourceProviders.CreateNewLeadSourceProvider' in 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\staging.one-trust.co.uk\b2c1e47d\c616ae6e\assembly\dl3\e3fbb1f6\4e0d3627_d6e3c701\FORTUNE.DLL'. Using the one in 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\staging.one-trust.co.uk\b2c1e47d\c616ae6e\App_Web_createnewleadsourceprovider.aspx.905d605a.lx9trvbk.0.cs'.      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\staging.one-trust.co.uk\b2c1e47d\c616ae6e\App_Web_createnewleadsourceprovider.aspx.905d605a.lx9trvbk.0.cs      313      



-------------

Source :: Line 312 onwards as follows:

  [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
    public class leadsourceproviders_createnewleadsourceprovider_aspx : global::FORTUNE.LeadSourceProviders.CreateNewLeadSourceProvider, System.Web.IHttpHandler {
       
        private static bool @__initialized;
       
        private static object @__stringResource;
       
        private static object @__fileDependencies;
       
        public leadsourceproviders_createnewleadsourceprovider_aspx() {
            string[] dependencies;
           
            #line 912304 "http://server//staging.one-trust.co.uk/LeadSourceProviders/CreateNewLeadSourceProvider.aspx.cs"
            ((System.Web.UI.Page)(this)).AppRelativeVirtualPath = "~/LeadSourceProviders/CreateNewLeadSourceProvider.aspx";
           
            #line default
            #line hidden
            if ((global::ASP.leadsourceproviders_createnewleadsourceprovider_aspx.@__initialized == false)) {
                global::ASP.leadsourceproviders_createnewleadsourceprovider_aspx.@__stringResource = this.ReadStringResource();
                dependencies = new string[2];
                dependencies[0] = "~/LeadSourceProviders/CreateNewLeadSourceProvider.aspx";
                dependencies[1] = "~/LeadSourceProviders/CreateNewLeadSourceProvider.aspx.cs";
                global::ASP.leadsourceproviders_createnewleadsourceprovider_aspx.@__fileDependencies = this.GetWrappedFileDependencies(dependencies);
                global::ASP.leadsourceproviders_createnewleadsourceprovider_aspx.@__initialized = true;
            }
            this.Server.ScriptTimeout = 30000000;
        }
I have created a new file (striped down the code to near bear essentials) -- as there is still no updating on the database table (the stored procedure is still the same).





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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <br />
        <asp:Button ID="Button_CreateNewLeadSourceProvider" runat="server" OnClick="Button_CreateNewLeadSourceProvider_Click"
            Text="Create New Lead Source Provider" Width="239px" />&nbsp;</div>
    </form>
</body>
</html>


.cs file as follows:

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;

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

    }
   
    protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
    {
        SqlDataSource FORTUNESQLDataSource = new SqlDataSource();

        FORTUNESQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["FORTUNEConnectionString"].ToString();

        FORTUNESQLDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
        FORTUNESQLDataSource.InsertCommand = "BackOffice.InsertNewLeadSourceProvider";

        FORTUNESQLDataSource.InsertParameters.Add("@LeadSourceProviderName", "Test 1");
        FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegisteredName", "Test 1");
        FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegistrationNumber", "1234567890");
        FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistered", "TRUE");
        FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistrationRef", "1234567890");
        FORTUNESQLDataSource.InsertParameters.Add("@Switchboard", "1234");
        FORTUNESQLDataSource.InsertParameters.Add("@LandlineFax", "1234");
        FORTUNESQLDataSource.InsertParameters.Add("@WebsiteURL", "test.com");
        FORTUNESQLDataSource.InsertParameters.Add("@EmailAddress", "post@test.com");
        FORTUNESQLDataSource.InsertParameters.Add("@ComplianceConfirmed", "TRUE");

        int RowsAffected = 0;

        try
        {
            RowsAffected = FORTUNESQLDataSource.Insert();
        }
        catch (Exception)
        {
            SQL_FailureHandler();
        }
        finally
        {
            FORTUNESQLDataSource = null;
        }
    }


    private void SQL_FailureHandler()
    {
        // TODO SQL Failure Handler needs to be scripted

    }
}


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks -- In the meantime, I have create a locally hosted (asp development server site) project containing the files as above (still connecting remotely to the same SQL 2005 server.

Purpose being -- in order to be able to debug the solution (as the remote debugging seemed not possible on the web server).

Still having the same issue -- the database table is not being updated. (but no errors now -- even after running the page) -- but obviously not quite there yet with a successful database update.
Do I need to create a 'Trigger' as well in order for the update to happen -- or does the Stored Procedure cater for this already?
When submitting form, I am getting the following error (via the Studio Output window):

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Web.dll
I managed to get this resolved in the end, by using the different structure as recommended at the top of this thread.  Modified a couple of lines to fit ... but wanted to add this to the conversation to confirm how it was solved and hopefully be useful for anyone else accordingly.

"
Good day,
you can try this code to retrieve and execute Stored procedures:

System.Data.SqlClient.SqlCommand scCommand = new System.Data.SqlClient.SqlCommand();
Command.CommandType = System.Data.CommandType.StoredProcedure;
Command.CommandText = StoredProcedureName;
Command.Parameters.Add("@RETURN_VALUE", System.Data.SqlDbType.Int).Direction = ParameterDirection.ReturnValue;

SqlConnection Connection1 = new SqlConnection(ConnectionString);

Command.Parameters.AddWithValue("@ColumnName", ValueToInsert);

try
{
     Connection1.Open();
     Command.Connection = Connection1;
     Command.ExecuteNonQuery();
 }
 catch (Exception ex)
 {
      //handle error here
 }
 finally
 {
     Connection1.Close();
}

Use this model. Hope it helps
"


modified script as follows______________________________

        protected void Button_CreateNewDatabaseEntry_Click(object sender, EventArgs e)
        {
            SqlDataSource MySQLDataSource = new SqlDataSource();

            MySQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString();


            System.Data.SqlClient.SqlCommand scCommand = new System.Data.SqlClient.SqlCommand();
            scCommand.CommandType = System.Data.CommandType.StoredProcedure;
            scCommand.CommandText = "BackOffice.InsertTestText";
            scCommand.Parameters.Add("@RETURN_VALUE", System.Data.SqlDbType.Int).Direction = ParameterDirection.ReturnValue;

            SqlConnection Connection1 = new SqlConnection(MySQLDataSource.ConnectionString);

            scCommand.Parameters.AddWithValue("@TestText", "Test Entry");

            try
            {
                Connection1.Open();
                scCommand.Connection = Connection1;
                scCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                //handle error here
            }
            finally
            {
                Connection1.Close();
            }
        }



Again, thank you for both contributors for their valued and apprieated contributions today :-)