Replacing <%= Control.ClientID %> in external javascript

Posted on 2009-12-17
Last Modified: 2012-05-08
I have an aspx with a control on it, lets call it txtDate, and I have an
external javascript file.

In the external javascript file, I have

var strContName = "document.getElementById('<%= txtDate.ClientID%>')";

which would work fine if the javascript was in the .aspx file, but when
adding the external javascript file via  
  System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<script type='text/javascript' language='JavaScript' src='DVLP.js'></script>");
            Page.ClientScript.RegisterStartupScript(this.GetType(), "OnLoad", sb.ToString());
the txtDate.ClientID does not get replaced with the client id.

Is there a way to do this.
Thanks all.

Question by:Star79
    LVL 29

    Accepted Solution

    Hi Star79,
    The easiest way is pass the control ID as parameter inside the defined function. This could solve your problem.
    function yourfunction(strControlID){
     //bla bla bla

    //call in your page

    Author Closing Comment

    It served the purpose

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    A Change in PHP Behavior with Session Write Short Circuit ( (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now