Click here to Skip to main content
15,921,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a Register Page..on submit button all the data can be store in the database ....but when i am refreshing the page data automatically insert into database without click to the submit button
C#
using System.Data.SqlClient;

public partial class radiobutton : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Visible = false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if((RadioButtonList1.SelectedValue=="")||(TextBox1.Text=="")||(DropDownList1.Text=="Select"))
        {
            Label1.Visible = true;
        }
        else
        {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Initial Catalog=dev; Data Source=.; Integrated Security=true";
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "insert into inserttest values('" + RadioButtonList1.SelectedItem.Text + "','" + TextBox1.Text + "','" + DropDownList1.SelectedValue + "','" + CheckBox1.Checked + "')";
        cmd.Connection = con;

        cmd.ExecuteNonQuery();
        con.Close();
       
        Response.Redirect(Request.Url.AbsolutePath);
        RadioButtonList1.Text = "";
        TextBox1.Text = "";
        DropDownList1.Text = "Select";
        Label1.Visible = false;
        
        }
    }
}

Please help me to solve this problem
Posted
Updated 29-Aug-12 21:18pm
v2

C#
//to avaoid pressing F5 key

document.onkeydown = function()
 {
          if(event.keyCode==116) {
          event.keyCode=0;
          event.returnValue = false;
          }
}

//to avoid refresh, using context menu of the browser

document.oncontextmenu = function() {event.returnValue = false;}
 
Share this answer
 
Comments
Devendra 1988 30-Aug-12 7:59am    
above code implement in load page or where it i write the code
_Amy 30-Aug-12 9:07am    
My +4. Good enough. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900