在使用按钮提交表单并更新 gridview 控件(位于 asp.net webform 的更新面板中)后,我试图显示 toastr 消息(信息、错误等)。谢谢
最佳答案
您可以使用 Page.ClientScript.RegisterStartupScript
方法来完成。示例:
Page.ClientScript.RegisterStartupScript(this.GetType(),
"toastr_message", "toastr.error('There was an error', 'Error')", true);
但我可能会创建一个方法或扩展方法来为我处理:
public static void ShowToastr(this Page page, string message, string title, string type = "info")
{
page.ClientScript.RegisterStartupScript(page.GetType(), "toastr_message",
String.Format("toastr.{0}('{1}', '{2}');", type.ToLower(), message, title), addScriptTags: true);
}
使用:
ShowToastr(this.Page, "Hello world!", "Hello");
如果您想要更健壮的东西,您可以将 type
参数设为 enum
。
关于c# - 添加 toastr javascript asp.net webform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15544908/