首页 > 解决方案 > 如何在 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();
    });
});

标签: javascriptc#jqueryasp.net

解决方案


推荐阅读