Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Client Side id of Server ControlsClient Side id of Server Controls
Previous
 
Next
New Post
5/2/2007 9:34 AM
 

Hi,

I'm writing a custom module using ASP.NET Ajax on DNN 4.5.1
I have a couple of JavaScript files that I include using the ScriptManager.Scripts.Add function on the server.

My question is how do I reference elements on the page in the JavaScript code.

Let's say I have an asp:Image server control That has an ID of Image1. On the client the img element will have an id that looks like this: dnn_ctr397_ViewModule_Image1

How can I reference the element from JavaScript using document.getElementById if I don't know in advanced the client side id?

Thanks,
Uri
 
New Post
5/2/2007 9:46 AM
 

Hi,

This is actually very simple, each asp.net control has a property called "ClientID" which returns the actual ID of the control on the client's page. This is the ID you can use getElementById  in your script.

There are a few ways to add the client id to a

  1. Add the script at the server side using the Page.ClientScript.RegisterClientScriptBlock function and then assign the client ID when you need to use the getElementById
  2. Use the server print tag  <%= Control.ClientID %> on your JavaScript.

Oren

 
New Post
5/2/2007 2:28 PM
 

Thanks Oren,

This is definitely a viable solution when you add the JavaScript as script blocks on the server.
The problem I'm having is that my JavaScript code is in .js files, and I can't seem to be able to put ASP <% %> tags in the .js files. I keep getting errors. Am I missing something?



Thanks,
Uri
 
New Post
5/2/2007 6:20 PM
 

Yes, your substitution would not be handled by the files with the js extension.  However, there is nothing stopping you from having a variable defined in your aspx/ascx file and accessing that variable in the js file.


 
New Post
5/3/2007 6:43 AM
 

This is why JS functions can accept parameters :-)

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Client Side id of Server ControlsClient Side id of Server Controls


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out