点击按钮上的提醒消息和字段

时间:2015-08-11 19:17:15

标签: javascript jquery vb.net textbox alert

我有一个方案需要解决。我有2个文本框用于名字,姓氏和一个按钮来保存这些字段。在页面加载上,我们正在填写 这些文本字段包含数据库中的一些数据,当我们更改任何文本字段中的文本并单击“保存”按钮时,我们需要显示消息/警告,如

"You're about change the name of the person, john, smith to Daniel, clark". Do you wanna proceed? 

如果用户使用“是”响应消息/警报,则只有我们应该允许这些更改进行保存。

代码段:

<asp:TextBox ID="txtfirstName"  runat="server" required="true" caption="First Name:" ></asp:TextBox>                           
               <asp:TextBox ID="txtlastName"  runat="server" caption="Last Name:"></asp:TextBox>

 <asp:Button ID="btnSave" runat="server"  Text="Save" CausesValidation="False"  />&nbsp;

背后:

我们需要在用户选择更改名称后才调用此代码

 Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

如果文本字段相同,则无需显示任何确认消息。 你能告诉我怎么做这个吗?

1 个答案:

答案 0 :(得分:0)

这应该做你想要的:)“

JavaScript已格式化,因此您可以轻松阅读它。您通常会将JavaScript放在1行,或者您可以创建一个函数并调用该函数。

同时查看confirm()JavaScript,您可以弹出一个正确的标题,它们是其他选项。

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:HiddenField ID="hdnfirstName" runat="server" Value="name" />
        <asp:HiddenField ID="hdnlastName" runat="server" Value="last" />
        <asp:TextBox ID="txtfirstName" runat="server"></asp:TextBox>
        <asp:TextBox ID="txtlastName" runat="server"></asp:TextBox>
        <asp:Button ID="btnSave" runat="server" Text="Save" runat="server" 
        OnClientClick="if(document.getElementById('hdnfirstName').value !== document.getElementById('txtfirstName').value || 
                      document.getElementById('hdnlastName').value !== document.getElementById('txtlastName').value){

                            if (confirm('You\'re about change the name of the ' + 
                                         document.getElementById('hdnlastName').value + ', ' + 
                                         document.getElementById('hdnfirstName').value + ' to ' + 
                                         document.getElementById('txtlastName').value + ', ' + 
                                         document.getElementById('txtfirstName').value + 
                                         '. Do you wanna proceed?')) 
                            {
                                return true; 
                            } else { 
                                return false; 
                            }
                      } else {
                        return true;
                      }" />
    </div>
    </form>
</body>
</html>
相关问题