Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Dear friends
i want to create a master page for my already existing default.aspx page , but that default page consists of javascript functions and jquery on header how to add this javascript functions and jquery with master page , so that it works, whether to call this javascript functions on Master page or Default page
 
My Master Page source code:
 
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="NewMaster.master.cs" Inherits="NewMaster" %>
 
<!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>CMS</title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
     <link rel="shortcut icon" href="favicon.ico" />
    <link rel="icon" type="image/gif" href="animated_favicon1.gif" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link href="gridview.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="styles/style.css" media="screen" />
    <link href="styles/styles_masterpage.css" rel="stylesheet" type="text/css" />
   <script language="javascript" type="text/javascript" src="scripts/Validation.js"></script>
   <%--<script language="javascript" type="text/javascript" src="scripts/Validation1.js"></script>
   <script language="javascript" type="text/javascript" src="scripts/Validation2.js"></script>--%>
    <style type="text/css">
        body, html
        {
            overflow-x: hidden;
        }
        .style1
    {
        width: 374px;
    }
    </style>
</head>
<script type="text/JavaScript">
<!--
    function MM_swapImgRestore() { //v3.0
        var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
    }
 
    function MM_preloadImages() { //v3.0
        var d = document; if (d.images) {
            if (!d.MM_p) d.MM_p = new Array();
            var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
                if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
        }
    }
 
    function MM_findObj(n, d) { //v4.01
        var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
            d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
        }
        if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
        for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
        if (!x && d.getElementById) x = d.getElementById(n); return x;
    }
 
    function MM_swapImage() { //v3.0
        var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
            if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }
//-->
</script>
<body>
    <form id="form1" runat="server">
   <div>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td colspan="2" width="100%">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td colspan="3">
                        <img src="images/header_strip.jpg" alt="" style="height: 0px; width: 100%" />
                    </td>
                </tr>
                <tr>
                    <td class="top_bg">
                        <div align="left">
                            <a href="">
                                <img name="top" hspace="8" border="0" id="top" src="images/Buttons/logo.jpg" />
                            </a>
                        </div>
                    </td>
                    <td align="center">
                        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/c1.gif" />
                    </td>
                    <td class="vv_bg">
                        <div align="right">
                            <a href="">
                                <img name="justclick" hspace="8" border="0" id="Img1" src="images/justclick.png" />
                            </a>
                        </div>
                    </td>
                    <td valign="middle" class="top_bg">
                    </td>
                </tr>
                <tr>
                    <td align="right" colspan="2">
                        <table>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
 
    <tr>
        <td align="center" width="100%" colspan="2">
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="nav_bg" style="background-color:#5C6A84"  >
                <tr>
                    <td align="right">
                        <table>
                            <tr>
                                <td>
                                    <asp:Label ID="Label2" runat="server" BorderColor="#7A2784" Font-Bold="True" Font-Italic="False"
                                        Font-Names="Times New Roman" Font-Size="Larger" ForeColor="#FFFFFF" Width="179px"
                                        Style="margin-left: 0px"> Welcome To CMS :<%= Session["username"]%> </asp:Label>
                                </td>
                                <td>
                                    <asp:LinkButton ID="LinkButton2" runat="server" Font-Bold="True" OnClick="LinkButton1_Click" style="color:#FFFFFF;">SignOut</asp:LinkButton>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td align="left" width="13%" class="menualign">
            <asp:Menu ID="menuSlide" runat="server" DataSourceID="XmlDataSource1" Orientation="Vertical"
                BackColor="Silver" align="left" Font-Size="Medium" Width="100%"
                StaticMenuItemStyle-HorizontalPadding="5px"
                onmenuitemclick="menuSlide_MenuItemClick">
                <DataBindings>
                    <asp:MenuItemBinding DataMember="MenuItem" NavigateUrlField="NavigateUrl" TextField="Text"
                        ToolTipField="ToolTip" />
                </DataBindings>
                <StaticMenuItemStyle ItemSpacing="8" CssClass="staticMenuItemStyle" />
                <StaticSelectedStyle CssClass="staticMenuItemSelectedStyle" />
                <DynamicMenuItemStyle CssClass="dynamicMenuItemStyle" />
 
            </asp:Menu>
        </td>
        <td align="left" width="87%" valign="top">
 
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
 
        </asp:ContentPlaceHolder>
 
        </td>
    </tr>
    <tr>
    <td height="35" bgcolor="#5C6A84"  colspan="2" width="100%">
            <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="style1" style="margin-left: 0px; color: #FFFFFF;">
                        Copyright &copy; 2009 All Rights Reserved.
                    </td>
                    <td width="60%" class="White" style="padding-right: 0px;" align="right">
                        <div style="padding-right: 0px; color: #FFFFFF;">
                            Powered By: <a href="http://www.Veeserv.com" target="_blank" class="b" style="color: #FFFFFF;">
                                VeeServ Technologies Pvt.Ltd</a>
                        </div>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
    <td  colspan="2" width="100%">
    <asp:XmlDataSource ID="XmlDataSource1" TransformFile="~/Menu/TransformXSLT.xslt"
    XPath="MenuItems/MenuItem" runat="server"></asp:XmlDataSource>
    </td>
    </tr>
</table>
           </div>
    </form>
</body>
</html>
 

 
MY DEFAULT PAGE SOURCE CODE IS :
 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CollegeDetails.aspx.cs" Inherits="CollegeDetails"
    meta:resourcekey="PageResource1" %>
 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register TagName="top" TagPrefix="Admin" Src="~/Top.ascx" %>
<%@ Register TagName="side" TagPrefix="Admin" Src="~/JMenu.ascx" %>
<%@ Register TagName="bottom" TagPrefix="Admin" Src="~/Bottom.ascx" %>
<!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>
    <title>COLLEGE DETAILS</title>
    <link rel="shortcut icon" href="favicon.ico" />
    <link rel="icon" type="image/gif" href="animated_favicon1.gif" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link href="gridview.css" rel="stylesheet" type="text/css" />
 
   <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
 
    <script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
    <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
 

    <script type="text/javascript">
        $(function() {
            $("#TextBox5").datepicker({
 

 
            });
 

 

            $("#TextBox6").datepicker({
 

 
            })
        });
    </script>
 

    <script language="javascript" type="text/javascript">
        function ltrim(s) {
            return s.replace(/^\s*/, "");
        }
        function trim(s) {
            //s=s.replace(/^\s*/,"");
            return s.replace(/^\s+|\s+$/g, "");
        }
 
        function cd() {
 

            var cname = document.getElementById("TextBox1");
            var founder = document.getElementById("TextBox2");
            var principal = document.getElementById("TextBox3");
            var address = document.getElementById("TextBox4");
            var asf = document.getElementById("TextBox5");
            var asd = document.getElementById("TextBox6");
            var stname = document.getElementById("TextBox7");
            var at = document.getElementById("TextBox8");
            var licno = document.getElementById("TextBox9");
            var pitno = document.getElementById("TextBox10");
 
            if (ltrim(cname.value) == "")
            { cname.style.background = 'Yellow'; alert("Please Enter College Name !"); cname.value = ""; cname.focus(); return false; }
            str = cname.value;
            var cnExp = /^([a-zA-Z\s\.])+$/;
            if (trim(cname.value).length != cname.value.length || str.match(cnExp) == null)
            { cname.style.background = 'Yellow'; alert("Enter College Name Should Be Alphabets !"); cname.focus(); return false; }
            else
            { cname.style.background = 'White'; }
 
            if (ltrim(founder.value) == "") {
 
                founder.style.background = 'Yellow'; alert("Please Enter Founder Name !"); founder.value = ""; founder.focus(); return false;
            }
            stfo = founder.value;
            var fExp = /^([a-zA-Z\s\.])+$/;
            if (trim(founder.value).length != founder.value.length || stfo.match(fExp) == null)
            { founder.style.background = 'Yellow'; alert("Enter Founder Name Should Be Alphabets !"); founder.focus(); return false; }
            else
            { founder.style.background = 'White'; }
 
            if (ltrim(principal.value) == "")
            { principal.style.background = 'Yellow'; alert("Please Enter Principal Name !"); principal.value = ""; principal.focus(); return false; }
            stpr = principal.value;
            var pExp = /^([a-zA-Z\s\.])+$/;
            if (trim(principal.value).length != principal.value.length || stpr.match(pExp) == null)
            { principal.style.background = 'Yellow'; alert("Enter Founder Name Should Be Alphabets !"); founder.focus(); return false; }
            else
            { principal.style.background = 'White'; }
 
            if (ltrim(address.value) == "")
            { address.style.background = 'Yellow'; alert("Please Enter Address !"); address.value = ""; address.focus(); return false; }
            else if (trim(address.value).length != address.value.length)
            { address.style.background = 'Yellow'; alert("Enter the address correctly !"); address.focus(); return false; }
            else
            { address.style.background = 'White'; }
 
            if (ltrim(asf.value) == "")
            { asf.style.background = 'Yellow'; alert("Please Enter Assessment Start From Date !"); asf.value = ""; asf.focus(); return false; }
            else
            { asf.style.background = 'White'; }
 
            if (ltrim(asd.value) == "")
            { asd.style.background = 'Yellow'; alert("Please Enter Academic Start Date !"); asd.value = ""; asd.focus(); return false; }
            else
            { asd.style.background = 'White'; }
 
            if (ltrim(stname.value) == "")
            { stname.style.background = 'Yellow'; alert("Please Enter Society / Trust Name !"); stname.value = ""; stname.focus(); return false; }
            stn = stname.value;
            var stExp = /^([a-zA-Z\s\.])+$/;
            if (trim(stname.value).length != stname.value.length || stn.match(stExp) == null)
            { stname.style.background = 'Yellow'; alert("Enter Society / Trust Name Should Be Alphabets !"); stname.focus(); return false; }
            else
            { stname.style.background = 'White'; }
 
            if (ltrim(at.value) == "")
            { at.style.background = 'Yellow'; alert("Please Enter Affiliated To !"); at.value = ""; at.focus(); return false; }
            stat = at.value;
            var atExp = /^([a-zA-Z\s\.])+$/;
            if (trim(at.value).length != at.value.length || stat.match(atExp) == null)
            { at.style.background = 'Yellow'; alert("Enter Affiliated To Should Be Alphabets !"); at.focus(); return false; }
            else
            { at.style.background = 'White'; }
 
            if (ltrim(licno.value) == "")
            { licno.style.background = 'Yellow'; alert("Please Enter License Number !"); licno.value = ""; licno.focus(); return false; }
            else if (trim(licno.value).length != licno.value.length)
            { licno.style.background = 'Yellow'; alert("Enter the license number correctly !"); licno.focus(); return false; }
            else
            { licno.style.background = 'White'; }
 
            if (ltrim(pitno.value) == "")
            { pitno.style.background = 'Yellow'; alert("Please Enter PAN / IT Number !"); pitno.focus(); return false; }
            else if (trim(pitno.value).length != pitno.value.length)
            { pitno.style.background = 'Yellow'; alert("Enter the PAN / IT number correctly !"); pitno.focus(); return false; }
            else
            { pitno.style.background = 'White'; }
        }
 
        function WindowClose() {
            window.opener.document.getElementById('Button1').click();
            window.close();
        }
    </script>
 
</head>
<body>
    <%--<script language="javascript" type="text/javascript" src="scripts/Validation4.js" ></script>--%>
 
    <script language="javascript" src="datetimepicker.js" type="text/javascript"></script>
 
    <form id="form1" runat="server">
    <div style="width: 100%;">
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="95%" valign="top" bgcolor="#FFFFFF">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td colspan="2">
                                <Admin:top ID="AT" runat="server" />
                            </td>
                        </tr>
                        <%--<table align="left" style="margin-bottom: 0px; width: 100%; height: 40%">--%>
                        <tr>
                            <td width="13%" style="background-color: Silver;" valign="top">
                                <table width="100%">
                                    <tr>
                                        <td>
                                            <Admin:side ID="BB" runat="server" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="87%" valign="top" style="background-color: #FFFFFF;" align="left">
                                <table width="100%" style="background-color: #FFFFFF;" align="center">
                                    <tr>
                                        <td colspan="3" align="center">
                                            <img src="images/Head/c1.PNG" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" width="100%">
                                            <table width="27%" align="center">
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label2" runat="server" CssClass="lbl" meta:resourcekey="Label2Resource1">College Name</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox1" runat="server" onkeypress="return AllowOnlyAlphabets(event)"
                                                            AutoCompleteType="Disabled" Width="150px" meta:resourcekey="TextBox1Resource1"></asp:TextBox>
                                                        <asp:Label ID="Label12" runat="server" Visible="False" meta:resourcekey="Label12Resource1"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label3" runat="server" CssClass="lbl" meta:resourcekey="Label3Resource1">Founder</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox2" runat="server" onkeypress="return AllowOnlyAlphabets(event)"
                                                            AutoCompleteType="Disabled" OnTextChanged="TextBox2_TextChanged" meta:resourcekey="TextBox2Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label4" runat="server" CssClass="lbl" meta:resourcekey="Label4Resource1">Principal</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox3" runat="server" onkeypress="return AllowOnlyAlphabets(event)"
                                                            AutoCompleteType="Disabled" meta:resourcekey="TextBox3Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label5" runat="server" CssClass="lbl" meta:resourcekey="Label5Resource1">Address</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox4" runat="server" AutoCompleteType="Disabled" Height="50px"
                                                            TextMode="MultiLine" meta:resourcekey="TextBox4Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label6" runat="server" CssClass="lbl" meta:resourcekey="Label6Resource1">Assessment Start From</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                            <asp:TextBox ID="TextBox5" runat="server" AutoCompleteType="Disabled" Width="100px"
                                                                meta:resourcekey="TextBox5Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label7" runat="server" CssClass="lbl" meta:resourcekey="Label7Resource1">Academic Start Date</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                            <asp:TextBox ID="TextBox6" runat="server" AutoCompleteType="Disabled" Width="100px"
                                                                meta:resourcekey="TextBox6Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label8" runat="server" CssClass="lbl" meta:resourcekey="Label8Resource1">Society / Trust Name</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox7" runat="server" onkeypress="return AllowOnlyAlphabets(event)"
                                                            AutoCompleteType="Disabled" meta:resourcekey="TextBox7Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label9" runat="server" CssClass="lbl" meta:resourcekey="Label9Resource1">Affiliated</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox8" runat="server" onkeypress="return AllowOnlyAlphabets(event)"
                                                            AutoCompleteType="Disabled" meta:resourcekey="TextBox8Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label10" runat="server" CssClass="lbl" meta:resourcekey="Label10Resource1">INC/License No</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox9" runat="server" AutoCompleteType="Disabled" Width="120px"
                                                            meta:resourcekey="TextBox9Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" width="49%">
                                                        <asp:Label ID="Label11" runat="server" CssClass="lbl" meta:resourcekey="Label11Resource1">PAN/IT No</asp:Label>
                                                    </td>
                                                    <td align="left" width="2%">
                                                        :
                                                    </td>
                                                    <td align="left" width="49%">
                                                        <asp:TextBox ID="TextBox10" runat="server" AutoCompleteType="Disabled" Width="120px"
                                                            meta:resourcekey="TextBox10Resource1"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="3" align="center" width="100%">
                                                        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" CssClass="Sub" OnClientClick="return cd();"
                                                            Font-Bold="False" meta:resourcekey="Button2Resource1" />
                                                        <asp:Button ID="Button1" runat="server" OnClientClick="WindowClose()" CssClass="Reset"
                                                            meta:resourcekey="Button1Resource1" OnClick="Button1_Click" />
                                                    </td>
                                                </tr>
                                                <tr id="trhdn" runat="server" visible="false" width="100%">
                                                    <td>
                                                        <asp:Label ID="Label1" runat="server" CssClass="lbl1" meta:resourcekey="Label1Resource1"
                                                            Font-Bold="False"></asp:Label>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <Admin:bottom ID="AB" runat="server" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
Posted 12-Sep-12 21:48pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Simply copy and paste your Javascript or JQuery code to an external JS file and link that file to master page. Otherwise if you don't want to use external JS file then you can directly move your Javascript or JQuery code to Master Page. It'll work.
 

 
All the best.
--Amit
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100