【问题标题】:Show alert before confirmation确认前显示警报
【发布时间】:2011-12-19 17:07:05
【问题描述】:

我想先显示警报,然后显示确认框。 仅当树视图包含子节点时才应显示警报。

到目前为止,这是我的代码,代码先显示确认框,然后显示警报。有什么方法可以切换它们,以便在确认之前显示警报?

//shows the confirmation box
    if (!Page.IsPostBack)
                {              
                        btn_save_delete.Attributes.Add("onclick", "return confirm('Deleting the Selected Item will also delete any existing Children under it! Confirm Changes?');");
                   }

//显示警告信息

protected void btn_save_delete_Click(object sender, EventArgs e)
        {

            if (tree_items.SelectedNode.ChildNodes.Count >= 1)
            {
                ScriptManager.RegisterStartupScript(this.tree_items, typeof(string), "Alert", "alert('Message here');", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.tree_items, typeof(string), "Alert", "alert('Message here2');", true);
            }
}

谢谢

更多细节:

我在网页上有一个树形视图和一个删除按钮。 树视图加载父节点和子节点。 如果我在选择带有子节点的父节点后单击删除,它应该给我一个警报,然后是一个确认框。如果我选择子节点或没有任何子节点的父节点,那么它应该只显示确认框。

【问题讨论】:

  • 如果您想回答您的问题,您可能需要提供更多信息。我觉得这太模糊了,无法掌握你在做什么。尝试提供一个概述,并解释第一段代码是什么。
  • 将你的 typeof(string) 更改为 this.GetType() 按照下面的示例进行操作.. 对我有用.. 让我知道它是否有效
  • @ArmedMonkey 我在解释中添加了详细信息,如果您需要更多详细信息,请告诉我

标签: c# asp.net .net


【解决方案1】:

为什么不尝试格式化您的警报..试试这个,您需要更改警报消息以适合您的示例...//strExport 是您将分配警报消息的内容..

string script = "alert('" + strExport + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true); 

【讨论】:

  • 它根本不起作用。这就是我所说的: string script = "alert('" + "Hi" + "');"; ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);
  • 它对我有用.. 我传入的字符串没有做quotedString ...可能还有其他问题.. 你的javascript调用是什么样的..?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-27
  • 1970-01-01
  • 2010-10-14
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 2016-09-24
相关资源
最近更新 更多