Click here to Skip to main content
16,015,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
submit button saving data more than once after hitting the submit button more than once

C#
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Library lib = new Library();
        string sEmpCode = Request.QueryString["empcode"].ToString();
        if (Request.QueryString["comcode"].ToString() == "MEHTASCL")
        {
            string company = Request.QueryString["comcode"].ToString();
            string location = "RNV";
            string strArea = ddrarea.SelectedValue.Trim();
            string strDepartment = ddrDepartment.SelectedValue.Trim();
            string strCatagory = ddrCatagory.SelectedValue.Trim();
            string strDesignation = lblDesignation.Text.Trim();
            string strSubCatagory = ddrSubCatagory.SelectedValue.Trim();
            string strTitle = txtTitle.Value.Trim();
            string strDescription = txtDescription.Value.Trim();
            string strStatus = ddrStatus.SelectedValue.Trim();
            string strsolution = txtsolution.Value.Trim();
            //int problem_id = Convert.ToInt32(lblProblem_id.Text.Trim());

            string ack = lib.InsertData(company, location, "1", strDesignation, sEmpCode, strDepartment, strArea, strCatagory, strSubCatagory, strTitle, strDescription, strStatus, strsolution);
        }
        lblMsg.Text = "Data Submitted Successfully";
    }
Posted
Updated 7-May-10 2:56am
v2

just disable your button after u click on it and enable it after the data is inserted so the user can'nt click twice
 
Share this answer
 
avijit1112010 wrote:
submit button saving data more than once after hitting the submit button more than once

That's what it should do. Hit Submit thrice, data will be submitted three times and so on.
If you don't want this, disable the button after user hits submit.


*After you achieve this, try refreshing the page. Duplicate data again. ;)
 
Share this answer
 
v2
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Library lib = new Library();
        string sEmpCode = Request.QueryString["empcode"].ToString();
        if (Request.QueryString["comcode"].ToString() == "MEHTASCL")
        {
            string company = Request.QueryString["comcode"].ToString();
            string location = "RNV";
            string strArea = ddrarea.SelectedValue.Trim();
            string strDepartment = ddrDepartment.SelectedValue.Trim();
            string strCatagory = ddrCatagory.SelectedValue.Trim();
            string strDesignation = lblDesignation.Text.Trim();
            string strSubCatagory = ddrSubCatagory.SelectedValue.Trim();
            string strTitle = txtTitle.Value.Trim();
            string strDescription = txtDescription.Value.Trim();
            string strStatus = ddrStatus.SelectedValue.Trim();
            string strsolution = txtsolution.Value.Trim();
            //int problem_id = Convert.ToInt32(lblProblem_id.Text.Trim());

            string ack = lib.InsertData(company, location, "1", strDesignation, sEmpCode, strDepartment, strArea, strCatagory, strSubCatagory, strTitle, strDescription, strStatus, strsolution);
        }
        lblMsg.Text = "Data Submitted Successfully";
    }

This is your code, you suggest declare your string(s) outside the button code with empty text.
string abc = "";

When you click the button, initially all the variables (string abc) are empty, so button function will fill the values. Next time when you click the button, the variables you declared outside the button scope are empty when the button function fills the values. I hope it will work gently. :doh:
Sample for you:


string sEmpCode = "";
        string company = "";
        string location = "";
        string strArea = "";
        string strDepartment = "";
        string strCatagory = "";
        string strDesignation = "";
        string strSubCatagory = "";
        string strTitle = "";
        string strDescription = "";
        string strStatus = "";
        string strsolution = "";
        string ack = "";
        lblMsg.Text = "";


Library lib = new Library();
        sEmpCode = Request.QueryString["empcode"].ToString();
        if (Request.QueryString["comcode"].ToString() == "MEHTASCL")
        {
            company = Request.QueryString["comcode"].ToString();
            location = "RNV";
            strArea = ddrarea.SelectedValue.Trim();
            strDepartment = ddrDepartment.SelectedValue.Trim();
            strCatagory = ddrCatagory.SelectedValue.Trim();
            strDesignation = lblDesignation.Text.Trim();
            strSubCatagory = ddrSubCatagory.SelectedValue.Trim();
            strTitle = txtTitle.Value.Trim();
            strDescription = txtDescription.Value.Trim();
            strStatus = ddrStatus.SelectedValue.Trim();
            strsolution = txtsolution.Value.Trim();
            //int problem_id = Convert.ToInt32(lblProblem_id.Text.Trim());

            ack = lib.InsertData(company, location, "1", strDesignation, sEmpCode, strDepartment, strArea, strCatagory, strSubCatagory, strTitle, strDescription, strStatus, strsolution);
        }
        lblMsg.Text = "Data Submitted Successfully";
 
Share this answer
 

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