我怎样才能得到这个 javascript 函数的结果并执行正确的存储过程?

How can i get the result of this javascript function and execute the proper stored procedure?

我有这个插入表单,允许用户插入服务器的名称,如果服务器不存在,它会插入,没问题,并给出 javascript 消息确认它是成功的,但是如果服务器已经存在但是因为它的 _Active 属性 = 0 它询问他是否想要激活它而我想要做的是如果用户按下 ok/yes 它激活该服务器并且如果用户按下它只是重新加载 page.ps:all the da。存储过程是否构造良好。

protected void btn_insert_server_Click1(object sender, EventArgs e)
    {
            
           DataAccess da = new DataAccess();
           DataTable dt = new DataTable();

           string ServerName = ServerNameADD.Value.ToString();
           if(ServerName.Length > 0)
           {
              dt = da.VerifyServer(ServerName);

              if (dt.Rows.Count == 0)
              {
                da.Insert_Server(ServerName);
                dt = da.GetServers();
                gridServers.DataSource = dt;
                gridServers.DataBind();

                string message = "Servidor Inserido com sucesso.";
                string script = "window.onload = function(){ alert('";
                script += message;
                script += "')};";
                ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);

              }
               else
               {
                string message = "Servidor já existe. Deseja torna-lo ativo? .";
                string script = "window.onload = function(){ ConfirmApproval('";
                script += message;
                script += "')};";
                ClientScript.RegisterStartupScript(this.GetType(), "PopUp", script, true);

                if (true)
                {
                    da.UpdateServerToActive(ServerName);
                    string messageSuccUp = "Servidor atualizado com sucesso.";
                    string scriptSuccUp = "window.onload = function(){ alert('";
                    scriptSuccUp += messageSuccUp;
                    scriptSuccUp += "')};";
                    ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
                }
                else if(false)
                {
                    da.GetServers();
                }
            }
           }
            
            
            

    }

好吧,我能够做到这一点的方式是,在前端我创建了一个名为 Confirm

的 onClientClick 事件
function Confirm() {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";
        if (confirm("Este Servidor já existe, deseja ativa-lo?")) {
            confirm_value.value = "Sim";
        } else {
            confirm_value.value = "Não";
        }
        document.forms[0].appendChild(confirm_value);
    }

它说的是“这个服务器已经存在,你想激活它吗?”并给出是或否的选择。 在服务器端,由于也触发了 onClick 事件,它会使用该值获取 confirm_value(是或否的答案),如果它的确认值是肯定的,则它会运行 if 语句,否则它只会刷新 gridView 和页面本身。

这是在 onClick 按钮事件中

string confirmValue = Request.Form["confirm_value"];
            if (confirmValue == "Sim")
            {
                da.UpdateServerToActive(ServerName);
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Servidor Ativado')", true);
                da.GetServers();
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Status do servidor mantidos')", true);
                da.GetServers();
            }