简体   繁体   English

使用Java验证先单击一个按钮

[英]Validate one button is clicked before another with Javascript

This is in ASP.NET. 这是在ASP.NET中。 We are using a ExtJS frontend, and have our own VB.NET controls to make all the Ext Forms and stuff. 我们使用的是ExtJS前端,并且拥有自己的VB.NET控件来制作所有Ext表单和内容。 However, I hope this can be done in plain javascript. 但是,我希望可以使用纯JavaScript完成。 There is already some Javascript on the page for the 'Test Connection' button click and handling the result. 页面上已经存在一些Java脚本,用于单击“测试连接”按钮并处理结果。

However, I need validation on the screen to make sure that a user tests the connection BEFORE saving the screen. 但是,我需要在屏幕上进行验证以确保用户在保存屏幕之前测试连接。 (Hits the test button before hitting the save button) -- EACH time they visit the screen. (在点击“保存”按钮之前,先按下测试按钮)-他们每次访问屏幕的时间。

Here is the code for the page: 这是页面的代码:

<%@ Page Language="VB" Inherits="Core.Web.EditBaseView" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function testConnection() {

            Global.mask('Testing Connection...');
            KBBConnectorController.TestConnection(function(result) { testConnectionCallback(result) });
        }

        function testConnectionCallback(result) {
            Global.unmask();
            if (result.Data.Result) {
                Global.alert("Connection to KBB Successful.");
            }
            else {
                Global.alertError(result.Data.Messages[0].Text, result.Data.ExceptionId);
            }
        }

        function Validate() {

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="display:none">
        <%  =Html.DropDownList("ddlMarketValues", TryCast(Model.MarketValues, SelectList))%>
    </div>
    <div>
        <%
            Using KBBForm As New WebControls.Forms.Form
                With KBBForm
                    .OnValidate = "Validate"
                    .ID = "KBB"
                    .ItemName = "connector"
                    With .Toolbar
                        .UseDefaultButtons = False
                        .AddButton(Forms.FormToolbar.ButtonType.Save)
                        .AddButton(Forms.FormToolbar.ButtonType.Cancel)
                        .AddButton("Test Connection", "testConnection", "icon-button-testconnection", , "Test connectione")
                    End With

                    With .CenterRegion
                        .Id = "centerRegion"
                        With .AddFieldSet("Activate Service")
                            .Id = "activate"
                            .LabelWidth = 0
                            Dim cb As New Forms.Control("IsActive", "", "", Model.IsActive, Forms.Control.ControlType.CheckBox)
                            cb.BoxLabel = "Activate Service"
                            .AddControl(cb)
                        End With

                        With .AddFieldSet("Connection Parameters")
                            .Id = "params"
                            .LabelWidth = 150
                            .AddControl(New Forms.Control("UserName", "", "User Name", Model.UserName, Forms.Control.ControlType.TextField))
                            .AddControl(New Forms.Control("Password", "", "Password", Model.Password, Forms.Control.ControlType.Password))
                            .AddControl(New Forms.Control("LoginUrl", "", "URL", Model.LoginUrl))
                            With .AddControl(New Forms.Control("ddlMarketValues", "", "Market Value", , Forms.Control.ControlType.ComboBox))
                                .Id = "ddlMarketValues"
                            End With
                        End With
                    End With
                    Response.Write(.ToString)
                End With
            End Using
            %>    
    </div>
    </form>
</body>
</html>

As you can see I put an OnValidate function in there but it's blank, and you can see that it's tied to the Form as well. 如您所见,我在其中放置了一个OnValidate函数,但它是空白的,并且您也可以看到它也与Form绑定在一​​起。 I tried fooling around with that but I could only put something together that would ask me to test every single time I clicked Save, and it wouldn't know if I already tested or not. 我尝试鬼混,但是我只能放一些东西,每次单击“保存”时都要求我进行测试,并且不知道是否已经测试过。

Any help? 有什么帮助吗? Thanks ahead of time. 提前谢谢。

-Scott -斯科特

为什么不只是隐藏保存按钮,直到按下测试连接并且连接可以工作?

Uh, this should work if I did understand you correctly. 嗯,如果我确实正确理解您的话,这应该可以工作。

  1. In the code which handles the result of the connection test , set a flag that indicates that the connection has been tested. 在处理connection test结果的代码中,设置一个标志,指示连接已经过测试。
  2. In the handler of the Save button check for that flag, and if it's not set display a message of some kind instead of actually performing the saving operation. 在“ Save按钮的处理程序中,检查该标志,如果未设置该标志,则显示某种消息,而不是实际执行保存操作。

Your flag could be global variable which is initially set to false this way the user would be required to run the test each time the visit the page. 您的标志可以是全局变量,该变量最初设置为false这样,每次访问该页面时,都将要求用户运行测试。

As on how you would override/intercept the Save buttons handler... uh... guess you'll have to extend the VB stuff for that. 至于您将如何覆盖/拦截“保存”按钮处理程序……呃……猜想您必须为此扩展VB内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何验证在单击按钮之前是否单击了锚标记(使用javaScript) - How to validate if an anchor tag was clicked before button click (Using javaScript) 在启用按钮之前,请验证表单中是否填充了文本区域并进行了多次选择单击 - Validate that textarea filled and multiselect clicked within form before enabling button 单击按钮之前激活Javascript功能 - Javascript Function activates before button is clicked onclick事件在点击按钮之前触发 - javascript - onclick event fires before button clicked - javascript 在单击另一个按钮之前检查用户单击了哪个按钮 - Checking which button was clicked by the user before clicking on another button Javascript对输入更改进行验证,仅在单击“提交”按钮时提交 - Javascript Validate on input change, only submit when Submit button clicked ValidateForm 如何在 JavaScript 中单击提交按钮时验证和显示文本 - ValidateForm How to validate and show text when submit button was clicked in JavaScript 当使用 Javascript 并且没有 jQuery 单击另一个菜单项的按钮(第一个的“堂兄”)时关闭一个菜单项的子菜单 - Close submenus of one menu item when another menu item's button ('cousin' of first) is clicked with Javascript and no jQuery 单击另一个按钮后如何隐藏和显示一个按钮? - how to hide and show one button after clicked on another button? 单击按钮后,如何在发送ajax之前调用我的validate函数? - How can I call my validate function before sending my ajax when a button is clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM