Solved

where to define javascript functions in a page with master page?

Posted on 2011-02-25
5
358 Views
Last Modified: 2012-05-11
hi experts
I saw some code samples put javascript functions in page header
but for a web page with master page ,there is no header in content page.
i tried put it in header of master page , seems not working
any advice?

thx
0
Comment
Question by:hukaka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34981404
Try inside Content PlaceHolder
<asp:Content ContentPlaceHolderID="contentPlaceHolder1" runat="server">
<script language="javascript">
// your js function here
</script>

Open in new window

0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 34981446
Make sure this contentplaceholder is inside the <head> tag at master page with runat="server"

Master Page
head runat="server"> 
<asp:ContentPlaceHolder ID="cphHead" runat="server" /> 
</head>

Open in new window

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

Open in new window


Try this
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34981483
I've shown various ways and places to include/import JSCRIPT. Now you can see I've imported it and I've also put some inline too. Either way is fine but it is preferred to import it.

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Portal.master.cs" Inherits="Portal.Portal" %>
<!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 id="Head1" runat="server">
    <title>Home Page</title>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /> 
    <!--[if IE 7]>
	<link href="css/ie7.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <!--[if IE 8]>
	<link href="css/ie8.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <link href="css/global_styles.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="js/admin_nav.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/datePicker.js"></script>
    <script type="text/JavaScript">
        <!--
        function popup() {
        alert("Hello World")
        }
        //-->
    </script>
    <asp:ContentPlaceHolder ID="head" runat="server">   
    <!-- This is your child or content page header. You can put Javascript tags here too.-->
</asp:ContentPlaceHolder>
</head>
<body>
    <div id="main_container">
        <div id="contentWrapper">
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                <!--- This is the place holder for Master Content.
            </asp:ContentPlaceHolder>	
        <!-- Closing Content Wrapper Div-->
        </div>
<!--Closing Wrapper Div-->        
</div> 
</body>
</html>

Open in new window

0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34981497
Please do not split points to me. The other replies have answered your question fully. I'm just showing you a full page example. I do not deserve any points for this answer.
0
 

Author Comment

by:hukaka
ID: 34981657
in fact I have already tried the the same way rajkumar suggested before asking this question.
the function was not called.still trying:(
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question