简体   繁体   中英

Validate one button is clicked before another with Javascript

This is in ASP.NET. We are using a ExtJS frontend, and have our own VB.NET controls to make all the Ext Forms and stuff. However, I hope this can be done in plain javascript. There is already some Javascript on the page for the 'Test Connection' button click and handling the result.

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. 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.
  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.

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.

As on how you would override/intercept the Save buttons handler... uh... guess you'll have to extend the VB stuff for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM