Jan
08
2007
Step 4: Using the JavaScriptServe control (and download solution)
Lets now use the control we created in step 3 :
Apart from referencing the javascriptserve.dll we just set page1.aspx too look like this:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="page1.aspx.cs" Inherits="page1" Title="Page 1" %>
<%@ Register TagPrefix="includer" Namespace="JavaScriptServe" Assembly="JavaScriptServe" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<includer:JSIncludeControl ID="whatever" runat="server">
<IncludeFiles>
<includer:IncludeFile Path="scripts/hello.js" />
</IncludeFiles>
</includer:JSIncludeControl>
This one includes the javascript hello.js
Test to click <a href="javascript:Hello();">here</a>
</asp:Content>
And page2.aspx:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="page2.aspx.cs" Inherits="page2" Title="Untitled Page" %>
<%@ Register TagPrefix="includer" Namespace="JavaScriptServe" Assembly="JavaScriptServe" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<includer:JSIncludeControl ID="whatever" runat="server">
<IncludeFiles>
<includer:IncludeFile Path="scripts/hello.js" />
<includer:IncludeFile Path="scripts/world.js" />
</IncludeFiles>
</includer:JSIncludeControl>
this one includes the javascripts hello.js and world.js
<br />
<br />
Test hello to click <a href="javascript:Hello();">here</a>
<br />
Test world to click <a href="javascript:World();" title="Page 2">here</a>
</asp:Content>
And by that we can now - in our "master derived" pages define which javascripts to be included - and they are all rendered inside the header portion of the html.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title><script type="text/javascript" src="/www/scripts/hello.js"></script>
<script type="text/javascript" src="/www/scripts/world.js"></script></head>
<body>
<form name="aspnetForm" method="post" action="page2.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIOTc1MzU0MTBkZNhYoCGJwfFIcwwEaN8iQb67tTCH" />
</div>
<div>
this one includes the javascripts hello.js and world.js
<br />
<br />
Test hello to click <a href="javascript:Hello();">here</a>
<br />
Test world to click <a href="javascript:World();" title="Page 2">here</a>
</div>
</form>
</body>
</html>
Now just download the solution and have a look at it. I will continue to work oon this project in future articles.