我使用C#4.0和SQL Server 2008 R2,我只需一个简单的按钮点击即可调用将数据保存到数据库并重定向页面的函数。
问题是客户端在此保存按钮上单击多个,然后我还将多个项目保存到数据库中。
我想避免客户端出错,这意味着客户端只能做1个clic = 1保存数据。
<dx:ASPxButton ID="ASPxButton_save" runat="server" Image-Url="~/images/Icon/Good-or-Tick-icon.png" Text="Enregistrer" Width="110px" onclick="ASPxButton_save_Click" ValidationGroup="Savebouton">
</dx:ASPxButton>
protected void ASPxButton_save_Click(object sender, EventArgs e)
{
string ErrPos = "";
try
{
ErrPos = "Affct CP DEST";
string FA_Choisi = ASPxTextBox_CP_dest.Text.Substring(0, 2);
string CLIENT_de_FA = ClientId.Substring(0, 2);
List<string> ClotList_FA = new List<string>();
ErrPos = "Affct Trans";
foreach (DataRow myRow in oOrdre_BL.Get_Tranporteur(ClientId).Tables["Le_Transporter"].Rows)
{
ClotList_FA.Add(myRow["LIBELLE"].ToString());
}
Pers_Client_Entrp oPersclientEntrp = GetOPersclientEntrp();
Pers_Ordre oPersOrdr = new
.......
if (ASPxCheckBox_NewDesti.Checked)
{
string ResTemp = oDest_BL.Compare_Dest(ClientId, ASPxTextBox_Desti_ID.Text, ASPxTextBox_RS_NOM_dest.Text, ASPxTextBox_ADRESSE_dest.Text);
if (!String.IsNullOrWhiteSpace(ResTemp))
{
lbl_err.Text = ResTemp;
}
else
{
Pers_Dest TheDest = new Pers_Dest();
TheDest.CodeDest = ASPxTextBox_Desti_ID.Text.Replace('-', ' ').Replace('\'', ' ');
TheDest.CodeClient = ClientId;
TheDest.RaisonSoc = ASPxTextBox_RS_NOM_dest.Text.Replace('-', ' ').Replace('\'', ' ');
TheDest.Adresse = ASPxTextBox_ADRESSE_dest.Text.Replace('-', ' ').Replace('\'', ' ');
TheDest.Cp = ASPxTextBox_CP_dest.Text;
TheDest.Ville = ASPxComboBox_VILLE_dest.Text;
TheDest.Pays = ASPxComboBox_PAYS_dest.Value.ToString();
TheDest.Tel = ASPxTextBox_TEL_dest.Text.Replace('-', ' ').Replace('\'', ' ');
TheDest.Fax = ASPxTextBox_FAX_dest.Text.Replace('-', ' ').Replace('\'', ' ');
TheDest.Email = ASPxTextBox_EMAIL_dest.Text.Replace('-', ' ').Replace('\'', ' ');
TheDest.Insee = ASPxTextBox_INSEE_dest.Text.Replace('-', ' ').Replace('\'', ' ');
TheDest.Siret = ASPxButton_SIRET_dest.Text.Replace('-', ' ').Replace('\'', ' ');
oDest_BL.CrUp_Dest(TheDest, true);
oPersOrdr.Ville = ASPxComboBox_VILLE_dest.Text;
Save_Part(oPersOrdr, oPersclientEntrp, OrdreID);
}
}
else
{
oPersOrdr.Ville = ASPxTextBox_VILLE_dest.Text.Replace('-', ' ').Replace('\'', ' ');
Save_Part(oPersOrdr, oPersclientEntrp, OrdreID);
}
catch (Exception ex)
{
lbl_err.Text = ex.Message;
if (ex.InnerException != null) { lbl_err.Text += "-->" +ex.InnerException.Message; }
Outils_IHM.SendingEmail("Save Odre --> Err Position: " + ErrPos + "-----" + lbl_err.Text, ClientId);
}
private void Save_Part(Pers_Ordre oPersOrdr, Pers_Client_Entrp oPersclientEntrp, string OrdreID)
{
oOrdre_BL.SaveUpdt_Ordre_BL(oPersOrdr, OrdreID);
string QuelleID = TempId;
if (!String.IsNullOrWhiteSpace(OrdreID))
{ QuelleID = OrdreID; }
if (oPersclientEntrp.TypPrint == "Zebra")
{ Response.Redirect("../Print/BonEticket_Web.aspx?ConnPrint=UnDirect&OdreID=" + QuelleID + "&CountOrdre=" + ASPxTextBox_NBR_COLIS.Text + "&TypeAR=" + TypeEnlev, false); }
else
{ Response.Redirect("../Print/BonEticket_Web.aspx?OdreID=" + QuelleID + "&CountOrdre=" + ASPxTextBox_NBR_COLIS.Text + "&TypeAR=" + TypeEnlev, false); }
Context.ApplicationInstance.CompleteRequest();
}
我有一个想法,当用户clic这个按钮时,它将调用客户端功能来禁用它。但我不知道它是如何以及它是否如我所愿。
答案 0 :(得分:0)
您可以使用下面提到的代码作为参考。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
var submit = 0;
function CheckIsRepeat() {
if (++submit > 1) {
alert('An attempt was made to submit this form more than once; this extra attempt will be ignored.');
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return CheckIsRepeat();" />
</div>
</form>
</body>
</html>
答案 1 :(得分:0)
在将数据保存到数据库之前禁用该按钮,然后保存数据,然后清除控件;然后再次启用按钮。
答案 2 :(得分:0)
<dx:ASPxButton ID="ASPxButton_save" runat="server" Image-Url="~/images/Icon/Good-or-Tick-icon.png" Text="Enregistrer" ClientInstanceName="ASPxButton_save" Width="110px" onclick="ASPxButton_save_Click" ValidationGroup="Savebouton">
<ClientSideEvents Click ="function(s,e) { MyBtnClick(s,e); } " />
</dx:ASPxButton>
function MyBtnClick(s, e) {
if (ASPxClientEdit.AreEditorsValid())
ASPxButton_save.SetVisible(false);
}