提问人:Tiago Silva 提问时间:6/23/2021 最后编辑:malarresTiago Silva 更新时间:6/23/2021 访问量:93
如何获取此 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 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();
}
}
}
}
答:
0赞
Tiago Silva
6/23/2021
#1
好吧,我能够做到这一点的方式是,在前端,我创建了一个名为 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(是或否答案),如果它是确认的 yes 值,它会运行 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();
}
评论