.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Confirmation MessageBox before insert data in a Table

Posted By:Syed Shakeer Hussain       Posted Date: August 15, 2010    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  

This Article Expalins you how to show Confirmation MessageBox before Insert data in a Table using C#

How to Show Confirmation MessageBox Before Insert data using JavaScript?

In a 'Submit' Button i am usign 'OnClientClick' attribute to show Confirmation MessageBox as Follows:

OnClientClick="return confirm('Are you sure, you want to Add this Record?');"

This Confirmation MessageBox will display two button 'Yes' and 'No' with Text for user confiramtion.If the User clicks on 'Yes" button the Record will Insert in a Table.If the user Clicks on 'NO' button the Transaction will be Cancelled.

Double Click on your Submit Button and write the Insert command code to insert data as follows:

protected void btnsubmit_Click1(object sender, EventArgs e)

cmd = new OleDbCommand("insert into student(Name,Rollno) values('" + textName.Text + "'," + txtID.Text + ")", conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "student");
GridView1.DataSource = ds.Tables["student"];
textName.Text = "";
txtID.Text = "";

The Submit Button of Soucre code as below :-

The Complete .aspx source page as follows:-

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Pagetitle>



<form id="form1" runat="server">


<asp:Button ID="btnconfirm" runat="server" Text="Submit" OnClick="btnsubmit_Click1" OnClientClick="return confirm('Are you certain you want to insert this product?');" />

<asp:TextBox ID="txtName" runat="server" Style="z-index: 101; left: 328px; position: absolute;

top: 72px" Width="120px">asp:TextBox>

<asp:TextBox ID="txtID" runat="server" Width="120px">asp:TextBox>

<asp:Label ID="lblName" runat="server" Text="Name">asp:Label>

<asp:Label ID="lblID" runat="server" Text="DeptID">asp:Label>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"

Style="z-index: 105; left: 0px; position: absolute; top: 0px">


<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

<asp:BoundField DataField="Rollno" HeaderText="DeptID" SortExpression="DeptID" />



<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db11ConnectionString %>"

ProviderName="<%$ ConnectionStrings:db11ConnectionString.ProviderName %>" SelectCommand="SELECT [Name], [DeptID] FROM [student]">






 Subscribe to Articles


Further Readings:

Author: Nikhil Kumar         Company URL: http://www.dotnetspark.com
Posted Date: August 21, 2010

it should be under the code snippets.
Nice code.
Author: Fahim         Company URL: http://www.dotnetspark.com
Posted Date: October 05, 2010

Nice Code thanks Shakeer

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend