• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Add to DB only on click of button

Hi Experts,

I have a ASP.net 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;
             conn.Open();
           //  dbCommand.ExecuteNonQuery();

           //

          lbl1.Text = "Order Accepted";
  conn.Close();
       }
----------------------------------------------------------------------------------------------------
0
henrym01
Asked:
henrym01
  • 2
1 Solution
 
dunglaCommented:
You can double click on btnSubmit from designer to bring up btnSubmit_Click()
protected void btnSubmit_Click (object sender, System.EventArgs e)
{
Cdate();
}
0
 
b1xml2Commented:
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.
0
 
b1xml2Commented:
blacklisted.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now