Add to DB only on click of button

Posted on 2005-05-05
Last Modified: 2010-04-16
Hi Experts,

I have a C sharp page, that at present reads values, displays and then adds to database. I wish it only to add after the user has clicked a button confirming the information, the page is split into .aspx and .cs, the aspx has the button control:

 <asp:button id="btnSubmit" runat="server" Text="Submit"></asp:button>


The .cs is:

 public void Cdate()
        labelcdate.Text = DateTime.Today.ToString("dd-MM-yyyy"); // put date in

        string strExample = CustIDHC.ToString();
        string strExample2 = CustIDHC.ToString();

        CID.Text = strExample;
        OID.Text = strExample;

        OleDbConnection conn = new OleDbConnection() ;
        string connStr;
        connStr = "Provider=Microsoft.Jet.OLEDB.4.0;";
        connStr  += "Data Source= " + Server.MapPath("ass.mdb");
        conn.ConnectionString = connStr;

        string queryString;
        queryString = "Insert into tOrder (CustID, OrderNbr, CDate) values( ";
        queryString += CustIDHC + ", ";
        queryString += OrderNbHS + ", '";
         queryString += labelcdate.Text;
         queryString += "')";

            OleDbCommand dbCommand = new OleDbCommand();
             dbCommand.CommandText = queryString;
             dbCommand.Connection = conn;
           //  dbCommand.ExecuteNonQuery();


          lbl1.Text = "Order Accepted";
Question by:henrym01
    LVL 13

    Expert Comment

    You can double click on btnSubmit from designer to bring up btnSubmit_Click()
    protected void btnSubmit_Click (object sender, System.EventArgs e)
    LVL 23

    Accepted Solution

    private void Page_Load(object sender,EventArgs e)
          if (! IsPostBack)
                btnSubmit_Click.Attributes["onclick"] = "return window.confirm('Do you wish to add this record');";

    this will cause a confirmation javascript window to appear. If they click Yes, it will let the button postback.
    LVL 23

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now