ASP Code
  Home arrow ASP Code arrow Automating Clientside Script Insertion Usi...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Automating Clientside Script Insertion Using ASP
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    2000-07-24

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Author: Lati Matata
    email : mlati@yahoo.com
    Date : 21/07/2000
    Tired of having to repeat the same Client-side support script's(JavaScript) for different pages?.
    This ASP Subroutine takes in the name of the function(s) as an array e.g


            Dim func_arr(1)
            func_arr(0)="function foo()"
            func_arr(1)="function foo1()"
           
    and the name of the central file that contains all the support javascript functions that you reuse
    (relative to the current file) e.g


            dim RelativeFilePath
            RelativeFilePath = "includes/client_script.asp"

    You can then call the function within the script tags of the page your wish to insert
    the javascript function.


        <!--#include virtual="/script.asp"-->
        .....
        <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
        <!--
        <%
        Dim func_arr(1),RelativeFilePath
        func_arr(0)="function foo()"
        func_arr(1)="function foo1()"
        RelativeFilePath = "includes/client_script.asp"
       
        call Print_Client_Script(func_arr,"includes/Client_Script.asp")
        %>
        //-->
        </SCRIPT>
        ......
       

    IMPORTANT!!.
    1. The JavaScript function MUST be well formed!--would work "as is"...if manually inserted.
    2. The client script file size should be not more than 64k for optimal performance

    I'll be happy to take any questions/comments, dont expect an immediate reply though!.


    ///the subroutine///////script.asp///begin////////////////////////////////////

    CONST MAX_ITERATIONS = 65536        '64K

    public sub Print_Client_Script(func_Name_arr,File_Name)

    'func_Name_arr ---array of names of the functions to print out
    'File_Name ---location of the file containing the function name(relative)

    dim fileObj,file_path,fileStream,i,code_str,ForReading
    dim func_Start_pos,iControl,Func_length,Func_End_pos
    ForReading = 1
    Set fileObj = CreateObject("Scripting.FileSystemObject")
    file_path = server.MapPath(File_Name) 'complete physical path to client script file
    if (fileObj.FileExists(file_path)) and isarray(func_Name_arr) = true then 'checking for file existence!
        Set fileStream = fileObj.OpenTextFile(file_path,ForReading)
        code_str = fileStream.ReadAll() 'reads the contents into one long string and then closes it
                                        'thats the reason for the limit on file size
        fileStream.Close()
            for i = 0 to Ubound(func_Name_arr) 'iterate through list of functions to search for
                            '(assumption the cilent script page has many other functions)
                func_Start_pos = instr(1,code_str,trim(func_name_arr(i)),1) 'look for the function in the string
                if func_Start_pos <> 0 or func_start_pos <> null then 'function name has been found
                    Func_End_pos = func_Start_pos 'initialise the various controls
                    iControl = 0
                    Func_Length = 0
                    do
                        if mid(code_str,Func_End_Pos,1) = chr(123) then 'looking for opening braces--"{"
                            iControl = iControl + 1
                        elseif mid(code_str,Func_End_Pos,1)=chr(125) then 'looking for closing brace--"}"
                            iControl =iControl - 1
                            if iControl = 0 then 'the iControl has go up then back down to zero(a full function!!)
                                exit do
                            end if
                        end if
                        Func_End_Pos = Func_End_Pos + 1 'move to the next character
                    loop while true AND Func_End_pos < MAX_ITERATIONS 'max_iterations..just incase..dont want to hung the server!
                    Func_Length = Func_End_Pos - func_Start_pos + 1 'add one to include the closing brace
                    Response.Write mid(code_str,Func_Start_pos,Func_length)&chr(13) 'right out the whole function string
                else
                    'ERROR the function has not been found!
                end if
            next
       
    else
        'ERROR the file does not exist
    end if
    Set fileObj = nothing
    end sub


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Discovering the value of WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! Download IBM WebSphere Portal V6.1 beta code

    Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z

    IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    NEW! Whitepaper: Delivering SOA solutions: service lifecycle management

    The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT