Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Sir..
My .aspx page having Master page in it
Quote:
<%@ 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" />
 
Posted
Comments
M.Thiyagaraja 25-Apr-14 10:37am    
There is no head section in the above page then how can i Add the reference of external JavaScript file into ASP.Net form

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.

XML
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="Registration.js" type="text/javascript"></script>
</asp:Content>
 
Share this answer
 
you can place two ways to access javascript file

In master page


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


In Content Page

C#
<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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900