asp.net - Toastr 通知不适用于 asp.net 网络表单
问题描述
我正在尝试在我的 ASP.NET Web 表单应用程序中使用 toastr 通知。我写了以下代码:
Toastr.cs
public static class Toastr
{
public static void ShowToastr(this System.Web.UI.Page page, string message, string title, string type)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "toastr_message", String.Format("toastr.{0}('{1}','{2}', { positionClass: 'toast-top-full-width', timeOut: 5e3, closeButton: !0, debug: !1, newestOnTop: !0, progressBar: !0, preventDuplicates: !0, onclick: null, showDuration: '300', hideDuration: '1000', extendedTimeOut:'1000', showEasing: 'swing', hideEasing: 'linear', showMethod: 'fadeIn', hideMethod: 'fadeOut', tapToDismiss: !1 });", type.ToLower(), message, title), addScriptTags: true);
}
}
然后在按钮上单击我正在这样做:
//code for insertion
cmd.ExecuteNonQuery();
Page.ClientScript.RegisterStartupScript(this.GetType(), "toastr_message", "toastr.success('Successfully added URD','Success!')", true);
在运行时我收到错误:
未捕获的 ReferenceError:在 test.aspx:407 中未定义 toastr
解决方案
页面中是否正确声明了 toastr 库?
jQuery也被声明了吗?
要测试页面上是否设置了所有内容:打开控制台并输入
toastr.info("title")
那应该显示一个简单的通知。如果这不起作用,那么您将开始收到错误消息以帮助您解决