【问题标题】:Open a Bootstrap Modal from C# asp.net从 C# asp.net 打开一个引导模式
【发布时间】:2017-09-27 00:58:21
【问题描述】:

我有一个大问题,我正在尝试从 c# 打开一个模式,但是我已经阅读了所有堆栈溢出的答案和问题,但任何一个都帮助了我。 这就是问题所在。

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            getProduct();
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "mdlError", "$('#mdlError').modal();", true);
        }
    }

这在我在 .net 中使用母版页时有效,但是当我运行应用程序时,什么都没有发生,代码只是运行但它不会崩溃。我调试了这段代码,好像有问题:

RegisterStartupScript   error CS0428: Cannot convert method group 'RegisterStartupScript' to non-delegate type 'object'. Did you intend to invoke the method?   

有人可以帮帮我吗? 我正在使用 Asp.NET 和 C#。 提前致谢。

【问题讨论】:

  • 首先,从服务器端调用脚本并不是一个好习惯。为什么不创建外部js文件并调用modal?还是在页面本身?
  • 如果执行某些方法有任何错误,如何调用模态?
  • 那是因为你试图通过 RegisterStartupScript 调用 modal。我的建议是创建一个调用modal的外部js文件?
  • 你能提供一些例子吗?

标签: c# jquery asp.net twitter-bootstrap


【解决方案1】:

正如 Andrew 建议的那样,您应该考虑定义一个客户端函数来打开弹出窗口。

function openModal() {
   $('#mdlError').modal({ show: true });
}

然后从后面的代码调用这个函数

ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 2016-05-09
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多