Javascript确认消息(YesNo动作命令) [英] Javascript Confirm message (YesNo action command)

查看:286
本文介绍了Javascript确认消息(YesNo动作命令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

祝大家好日子。单击出现的确认消息后,我遇到了如何执行命令的问题。如果我按是按钮,它将执行某个命令,而如果按否按钮,它将提示一个警告消息。感谢你们能帮我解决这个问题。请在下面找到我的代码。



这是我执行命令的代码,如果是,请按



Dear All,
Good day to all of you. I having problem on how to execute my command once I have click on Confirm message that appear. If I would press Yes button, it will execute a certain command while if press No Button, it will prompt an alert message. Appreciate if you guys could help me on this matter. Please find below my code.

Here is my code for the command to execute if Yes been press

Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
       Dim strSQL As New StringBuilder
       If txtboxvalue.Text = "" Then
           txtboxvalue.Focus()
           cf.messagebox("There is no value to delete. Please select value !", Me)
           Exit Sub
       Else
           cf.msgboxyesno("Are you sure to delete this data !", Me)
           ' If msgboxyesno=Yes is clicked Then
           '    execute certain command
           ' else
           '    Exit Sub
           ' End If

       End If







这是我的代码,用于显示确认信息框






Here is my code to display the confirm messagebox

Public Sub msgboxyesno(ByVal sMsg As String, ByVal m As Page)

    Dim sb As New StringBuilder()
    Dim oFormObject As New System.Web.UI.Control

    sMsg = sMsg.Replace("'", "\'")
    sMsg = sMsg.Replace(Chr(34), "\" & Chr(34))
    sMsg = sMsg.Replace(vbCrLf, "\n")
    sMsg = "<script language=javascript>confirm(""" & sMsg & """)</script>"

    sb = New StringBuilder()
    sb.Append(sMsg)

    For Each oFormObject In m.Controls
        If TypeOf oFormObject Is HtmlForm Then
            Exit For
        End If
    Next

    oFormObject.Controls.AddAt(oFormObject.Controls.Count, New LiteralControl(sb.ToString()))

End Sub

推荐答案

你做错了。



在页面上写javascript函数。对于btnDelete提出问题并返回结果。如果结果为是,则服务器端代码触发,如果答案为否(false),则永远不会到达服务器端。



您的代码应如下所示:

aspx文件

You're doing it wrong.

Write javascript function on the page. For btnDelete raise the question and return the result. If the result is yes, server side code triggers, if the answer is no (false) it will never get to server side.

Your code should look like this:
aspx file
<asp:button id="btnDelete" runat="server" onclick="btnDelete_Click" onclientclick="javascript: return confirmDelete();" xmlns:asp="#unknown" />

<script type="text/javascript">
function confirmDelete() {
if (your-text-box.value.trim == "")
return confirm("There is no value to delete. Please select value !");
}
else
{
return confirm("Are you sure to delete this data ?");
}
</script>






$你的aspx.vb文件中的b $ b




in your aspx.vb file

Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
           '    execute your delete





您不需要服务器端msgboxyesno方法。



如果这有帮助请花时间接受解决方案。谢谢。



You don't need server side msgboxyesno method.

If this helps please take time to accept the solution. Thank you.


这篇关于Javascript确认消息(YesNo动作命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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