[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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

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.

1 Solution
David H.H.LeeCommented:
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
Star79Author Commented:
It served the purpose

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now