如何将javascript文件(.js)附加到具有母版页的asp.net网页 [英] How to attach javascript file (.js) into asp.net web page which has master page

查看:60
本文介绍了如何将javascript文件(.js)附加到具有母版页的asp.net网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生..

我的.aspx页面中有母版页

Dear Sir..
My .aspx page having Master page in it

Quote:

<%@ Page Title =Language =C#MasterPageFile =〜/ MasterPage.masterAutoEventWireup =trueCodeFile =second .aspx.csInherits =second%>





< asp:Content ID =Content1ContentPlaceHolderID = headRunat =Server>



< style type =text / css>

.style2

{

宽度:100%;

border-collapse:collapse;

border:2px solid#0000ff;

背景颜色:#FF99CC;

}

.style3

{

字体-family:Courier New,Courier,monospace;

font-size:medium;

颜色:#0000FF;

}

.style4

{

宽度:43px;

}

.style5

{

}

< / style>



< asp:Content ID = Content2ContentPlaceHolderID =ContentPlaceHolder1Runat =Server>





我的JavaScript文件

函数userValid(){

var名称,LName,FName;

FName = document.getElementById(txt_Fname )。value;

LName = document.getElementById(txt_Lname)。value;

if(FName =''&& LName =''&& Name ==''){

alert(Enter All Fields);

返回false;

}



if(FName =='')

{

alert(请输入名字)

返回false;

}

如果(LName =='')

{

alert(请输入姓氏)

返回false;

}



if(姓名==''){

提醒(请输入登录ID);

返回false;

}

返回true;

}

注册页面
< asp:Label ID =Label1runat =serverBorderColor =#6600FF

BorderStyle =DoubleText = 名字宽度=100px>

< asp:TextBox ID =txt_Fnamerunat =serverBorderColor =#99FF33

ForeColor =# 660033宽度=180px>

 
< asp:Label ID =Label2runat =serverBorderColor =#6600FF

BorderStyle =DoubleText =姓氏宽度=100px>

< asp:TextBox ID =txt_Lnamerunat =serverBorderColor =#99FF33

ForeColor =#660033Width = 180px>

 
  < asp:Button ID =Btn_Saverunat =serverBackColor =#CC66FFText =Save

OnClientClick =return userValid(); onclick =Btn_Save_Click/>

 

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="second.aspx.cs" Inherits="second" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<style type="text/css">
.style2
{
width: 100%;
border-collapse: collapse;
border: 2px solid #0000ff;
background-color: #FF99CC;
}
.style3
{
font-family: "Courier New", Courier, monospace;
font-size: medium;
color: #0000FF;
}
.style4
{
width: 43px;
}
.style5
{
}
</style>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


My JavaScript File
function userValid() {
var Name,LName,FName;
FName=document.getElementById("txt_Fname").value;
LName=document.getElementById("txt_Lname").value;
if (FName ='' && LName ='' && Name == '' ) {
alert("Enter All Fields");
return false;
}

if (FName =='')
{
alert ("Please Enter the First Name")
return false;
}
if (LName =='')
{
alert ("Please Enter the Last Name")
return false;
}

if (Name == '') {
alert("Please Enter Login ID");
return false;
}
return true;
}

Registration Page
<asp:Label ID="Label1" runat="server" BorderColor="#6600FF"
BorderStyle="Double" Text="First Name" Width="100px">
<asp:TextBox ID="txt_Fname" runat="server" BorderColor="#99FF33"
ForeColor="#660033" Width="180px">
 
<asp:Label ID="Label2" runat="server" BorderColor="#6600FF"
BorderStyle="Double" Text="Last Name" Width="100px">
<asp:TextBox ID="txt_Lname" runat="server" BorderColor="#99FF33"
ForeColor="#660033" Width="180px">
 
  <asp:Button ID="Btn_Save" runat="server" BackColor="#CC66FF" Text="Save"
OnClientClick="return userValid();" onclick="Btn_Save_Click" />
 

推荐答案

创建注册表单并将其与母版页关联时,它将具有标题的内容控件。只需将脚本标签放在那里注册js。



When you create you create the registration form and associate it with the master page it will have a Content control for the header. Just place the script tag for you registration js there.

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="Registration.js" type="text/javascript"></script>
</asp:Content>


你可以通过两种方式访问​​javascript文件



在母版页中





you can place two ways to access javascript file

In master page


<head runat="server">
 <script src="Registration.js" type="text/javascript"></script>
</head>





在内容页面





In Content Page

<asp:content id="Content1" contentplaceholderid="head" runat="server" xmlns:asp="#unknown">
    <script src="Registration.js" type="text/javascript"></script>
</asp:content>
<asp:content id="Content2" contentplaceholderid="head" runat="server" xmlns:asp="#unknown">

</asp:content>


这篇关于如何将javascript文件(.js)附加到具有母版页的asp.net网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆