单击确定按钮时,Javascript确认消息框未触发gridview onrowdeleting事件 [英] Javascript confirm messagebox is not firing gridview onrowdeleting event when ok button is clicked
问题描述
我正在使用网格视图来编辑和删除具有SQL Server数据库的asp.net中的用户帐户。我已经完成了更新数据库中的记录并删除了但我需要在将记录删入数据库之前显示确认消息。
为此我使用了gridview_rowupdating event和gridview_rowdeleting事件。显示确认消息框但是当我单击确认消息框中的确定按钮时,它不会触发事件gridview_rowdeleting事件。我只是认为它没有调用事件,这就是为什么我初始化onclientclick事件为asp按钮调用确认消息框,它正在获取输出,但当我点击确定按钮没有触发任何东西。
我会分享代码请有人解释我处理这个案子的情况
我尝试了什么:
ASP按钮:
I am using grid view for editing and deleting the user account in the asp.net having SQL server database. I have done updating the record in the database and deleting as well but i require to show a confirmation message before deleting the record into the database.
For this i used gridview_rowupdating event and gridview_rowdeleting event. Confirm message box is displayed but when i click OK button in the confirm message box it doesn't take to fire the event gridview_rowdeleting event. I am just thinking it doesn't call the event that is why i initialized onclientclick event for asp button to call the confirm messagebox and it is getting the output but when i click OK button not firing anything.
I will share the code please anybody explain me the situation to handle this case
What I have tried:
ASP Button:
<asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="btn btn-link text-center" ToolTip="Delete User Details" CommandName="Delete" UseSubmitBehavior="false" CausesValidation="false" OnClientClick="return ConfirmDeletion();" OnClick="btnDelete_Click" />
Javascript:
Javascript:
function ConfirmDeletion() {
debugger;
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Are you sure you want to delete the record?") == true)
confirm_value = "Yes";
else
confirm_value = "No";
}
删除按钮代码示例背后:
Delete Button Code Behind for sample:
protected void btnDelete_Click(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}
推荐答案
尝试:
OnClientClick="if(!ConfirmDeletion()){return false;}"
很多时候,客户端点击
事件处理程序会有额外的代码添加执行回发。通过在开始时添加无条件 return
,可以防止该代码运行用户选择的任何选项。
Quite often, the client-side click
event handler will have extra code added to perform a post-back. By adding an unconditional return
at the start, you prevent that code from running whichever option the user picks.
这篇关于单击确定按钮时,Javascript确认消息框未触发gridview onrowdeleting事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!