javascript - 如何在 ASP.NET 中的 MasterPage 中的 PageLoad 上调用 Javascript 函数
问题描述
如果用户未使用 jquery 插件进行身份验证,我想显示通知,但我不知道该怎么做。它一直说该功能未定义。我必须在我已经尝试过的 masterpage.ge 底部加载脚本。此代码也在 masterpage.cs 上
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowNoty", "ShowNoty('error','Accesso não autorizado.');", true);
FormsAuthentication.RedirectToLoginPage();
}
else
{
}
}
js函数
$(window).on('load', function () {
$(document).ready(function ShowNoty(type, message) {
var noty = new Noty({
theme: 'bootstrap-v4',
text: message,
type: type,
timeout: 3000,
animation: {
open: 'animated bounceInRight', // Animate.css class names
close: 'animated bounceOutRight' // Animate.css class names
},
layout: 'topRight',
onHover: function () {
noty.Close();
},
}).show();
});
});
解决方案
推荐阅读
- javascript - LigtningChart JS 缩放带图上的日期时间轴
- r - ggplot2 中图例的自定义顺序,因此它与图中因子的顺序不匹配
- powershell - 从位于多个远程服务器上的文本文件中选择所需的内容并写入执行脚本的 csv 日志
- mysql - sql/presto:如何查找每天之前存在但不存在于当天的记录
- python - B 的因式分解无法完成,没有计算任何特征值或特征向量
- python - 如何接受输入到数组中并对其进行排序?
- flutter - getter 中的 switch 语句
- javascript - 在 nextjs 中使用 JavaScript 的 Jquery
- angular - 当它们在 spectator.component 之外时如何模拟 / spyOn 常量
- react-native - React Native Google API 没有响应