gpt4 book ai didi

c# - 如何在子页面上设置javascript?

转载 作者:行者123 更新时间:2023-12-02 19:58:15 25 4
gpt4 key购买 nike

我有两个页面,一个母版页和一个子页。如何在子页面上设置javascript?

我想使用javascript在子页面上实现textchange功能。

最佳答案

母版页:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="ContentPlaceHolderHead" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolderMain" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

子页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebForm1" %>
<asp:Content ID="ContentHead" ContentPlaceHolderID="**ContentPlaceHolderHead**" runat="server" >
<script language="javascript" type="text/javascript">
// You can write a javascript code HERE...
</script>
</asp:Content>
<asp:Content ID="ContentMain" ContentPlaceHolderID="ContentPlaceHolderMain" runat="server" >
<!-- Content -->
</asp:Content>

或者,您可以在子页面的代码隐藏文件中添加javascript文件。

protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl somejs = new HtmlGenericControl("script");
somejs.Attributes.Add("type", "text/javascript");
somejs.Attributes.Add("src", ResolveClientUrl("~/Content/js/something.js"));
this.Page.Header.Controls.Add(somejs);
}

关于c# - 如何在子页面上设置javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8351961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com