如何解决我怎样才能得到这个 javascript 函数的结果并执行正确的存储过程?
我有这个插入表单,让用户插入服务器的名称,如果服务器不存在,它插入,没问题,并给出一个 javascript 消息确认它成功,但如果服务器已经存在,但作为它的_Active property = 0 它询问他是否想激活它,我想要做的是如果用户按下确定/是它激活该服务器,如果用户按下否它只是重新加载页面.ps:所有的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",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(),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(是或否答案),如果它是一个确认的 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('Status do servidor mantidos')",true);
da.GetServers();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。