如何在c#中关闭带有警报消息的浏览器选项卡

时间:2015-05-04 08:16:34

标签: c#

我一直在尝试使用下面的代码来执行,但是消息框没有显示,而tab也没有接近。

ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "alert('Record Deleted successfully.Note: This tab is now getting close');", true);

所以我只是删除了警告'从上面的代码中获取代码,然后获取执行并关闭选项卡。但我还想显示通知消息框怎么样?

ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "window.close();", true);

3 个答案:

答案 0 :(得分:2)

将两个调用合并为一个,然后逐个调用:

ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "alert('Record Deleted successfully.Note: This tab is now getting close');window.close();", true);

答案 1 :(得分:0)

这样写..

class App
{
     private readonly Dictionary<Type, object> delegateMap;

     void Add<T>(Action<SomeClass<T>> foo)
     {
         object tmp;
         if (!delegateMap.TryGetValue(typeof(T), out tmp))
         {
              tmp = new List<Action<SomeClass<T>>>();
              delegateMap[typeof(t)] = tmp;
         }
         List<Action<SomeClass<T>> list = (List<Action<SomeClass<T>>) tmp;
         list.Add(foo);
     }

     void InvokeActions<T>(SomeClass<T> item)
     {
         object tmp;
         if (delegateMap.TryGetValue(typeof(T), out tmp))
         {
             List<Action<SomeClass<T>> list = (List<Action<SomeClass<T>>) tmp;
             foreach (var action in list)
             {
                 action(item);
             }
         }
     }
}

答案 2 :(得分:0)

从javascript尝试

<script type="text/javascript">
    function Showalert() {
        alert('Call JavaScript function from codebehind');
        window.close();
    }
</script>

然后从您的代码隐藏方面调用它,如果你想要的话。

ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert();", true);
这会对你有所帮助。 感谢名单。

相关问题