提交按钮保存数据,然后再提交一次 [英] submit button saving data more then once

查看:129
本文介绍了提交按钮保存数据,然后再提交一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多次点击提交按钮后,多次提交按钮保存数据

submit button saving data more than once after hitting the submit button more than once

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";
    }

推荐答案

只需在您单击按钮后禁用按钮,并在插入数据后启用它,这样用户就不会再单击两次
just disable your button after u click on it and enable it after the data is inserted so the user can''nt click twice


avijit1112010写道:
avijit1112010 wrote:

提交按钮在多次单击提交按钮后多次保存数据

submit button saving data more than once after hitting the submit button more than once


那是应该做的.点击提交"三次,数据将被提交3次,依此类推.
如果您不希望这样做,请在用户点击提交"后禁用该按钮.


*完成此操作后,请尝试刷新页面.再次复制数据. ;)


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. ;)


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 = "";


当您单击按钮时,最初所有变量(字符串abc)均为空,因此按钮功能将填充这些值.下次单击按钮时,当按钮函数填充值时,在按钮作用域之外声明的变量为空.我希望它会轻柔地工作. :doh:
样品供您选择:



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";


这篇关于提交按钮保存数据,然后再提交一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆