我如何在Master Page的内容页面中调用javascript函数

时间:2021-10-13 01:32:43

This is my Master Page

这是我的母版页

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Master.master.cs" Inherits="Master.Master" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title></title>

    <script type="text/javascript">


        function checkMatchPassword() {
            swal("Error!", ".......", "error");
        }

    </script>
    <asp:ContentPlaceHolder ID="head" runat="server">

    </asp:ContentPlaceHolder>

</head>

This is my Content Page's Class (Master Page's Child)

这是我的内容页面的类(母版页的孩子)

ScriptManager.RegisterClientScriptBlock(this, GetType(), "Password", "checkMatchPassword();", true);

I want to call a javascript function in Master Page's content page. But the code I wrote is not working. Please help.

我想在Master Page的内容页面中调用javascript函数。但是我写的代码不起作用。请帮忙。

2 个解决方案

#1


0  

This code should work. You must put definition for "swal" function in master page.

这段代码应该有效。您必须在母版页中放置“swal”函数的定义。

#2


0  

Your reference to SweetAlert is missing:

您缺少对SweetAlert的引用:

Download the SweetAlert (https://github.com/t4t5/sweetalert) manuel and add the missing references:

下载SweetAlert(https://github.com/t4t5/sweetalert)manuel并添加缺少的参考资料:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Master.master.cs" Inherits="Master.Master" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title></title>

    <script src="scripts/sweetalert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="content/sweetalert.css">

    <script type="text/javascript">


        function checkMatchPassword() {
            swal("Error!", ".......", "error");
        }

    </script>
    <asp:ContentPlaceHolder ID="head" runat="server">

    </asp:ContentPlaceHolder>

</head>

#1


0  

This code should work. You must put definition for "swal" function in master page.

这段代码应该有效。您必须在母版页中放置“swal”函数的定义。

#2


0  

Your reference to SweetAlert is missing:

您缺少对SweetAlert的引用:

Download the SweetAlert (https://github.com/t4t5/sweetalert) manuel and add the missing references:

下载SweetAlert(https://github.com/t4t5/sweetalert)manuel并添加缺少的参考资料:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Master.master.cs" Inherits="Master.Master" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title></title>

    <script src="scripts/sweetalert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="content/sweetalert.css">

    <script type="text/javascript">


        function checkMatchPassword() {
            swal("Error!", ".......", "error");
        }

    </script>
    <asp:ContentPlaceHolder ID="head" runat="server">

    </asp:ContentPlaceHolder>

</head>