Hi Good Evening...,
I have a button in aspx page
In Button click event code i am trying to insert data in sqlserver.
once button clicked the data was stored in database ,its working fine but my problem is when i am click the button multiple times the data was inserted many time,
how can i restrict to allow the user only one time click ?
Please Provide me Solution as Possible as Early...
Thanks in Advance
P.Vinay Kumar
Loading
Neha SharmaPosted Oct 25, 2012, 8:11 AM
Neha SharmaPosted Oct 25, 2012, 8:32 AM
vinay kumarPosted Oct 25, 2012, 8:25 AM
vinay kumarPosted Oct 25, 2012, 8:23 AM
This is not working in my application
is there any other solution.....
vinay kumarPosted Oct 25, 2012, 8:20 AM
But My app , i just sending parameters to method and getting result...
is there any other solution.....
vinay kumarPosted Oct 25, 2012, 8:02 AM
Kunal VaishyaPosted Oct 25, 2012, 7:24 AM
do one thing first time when you click the save buttons then after save clear the data in controls and after when you click on save buttons then firstly check it control is empty or not if empty then return from event or skip to save the record
Satyapriya NayakPosted Oct 25, 2012, 7:19 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Insert
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
protected void btn_register_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@Name,@Email)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Email", txtEmail.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
clear();
}
void clear()
{
txtName.Text = "";
txtEmail.Text = "";
}
}
}
Sivaraman DhamodaranPosted Oct 25, 2012, 7:13 AM
Secondly, If you don't want primary key column on your database, you front end should check the data already entered. If so, should return from the handler of the the button.
The above methods are functionally right.
The worst answer is:
Disable the button on the button click handler, after the insert operation. Your user now can click only once. If they complain about the button disabled after a single click, just react to them like
Cool Man