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 SharmaRank #569 · 4.3K reputationPosted Oct 25, 2012, 4:11 AM EDT
Sivaraman DhamodaranRank #40 · 34.5K reputationPosted Oct 25, 2012, 3:13 AM EDT
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
Satyapriya NayakRank #47 · 31.5K reputationPosted Oct 25, 2012, 3:19 AM EDT
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 = "";
}
}
}
Kunal VaishyaRank #990 · 2K reputationPosted Oct 25, 2012, 3:24 AM EDT
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
vinay kumar56 reputationPosted Oct 25, 2012, 4:02 AM EDT
vinay kumar56 reputationPosted Oct 25, 2012, 4:20 AM EDT
But My app , i just sending parameters to method and getting result...
is there any other solution.....
vinay kumar56 reputationPosted Oct 25, 2012, 4:23 AM EDT
This is not working in my application
is there any other solution.....
vinay kumar56 reputationPosted Oct 25, 2012, 4:25 AM EDT
Neha SharmaRank #569 · 4.3K reputationPosted Oct 25, 2012, 4:32 AM EDT