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.0Dnn adding a prefix to textbox control id in my usercontrol. My java script is hard coded with the tDnn adding a prefix to textbox control id in my usercontrol. My java script is hard coded with the t
Previous
 
Next
New Post
3/2/2009 8:33 PM
 

Dnn adding a prefix to textbox control id in my usercontrol. My java script is hard coded with the textbox control id 

My module has a WebControl "GTier.ascx" which uses a Third Party "Tree Structure"
The code is like this
HTML:
------
<%@ Import Namespace="obout_ASPTreeView_2_NET" %>
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="GTier.ascx.vb" Inherits="Kimco.DNN.Modules.GTier.GTier" %>
 <ASP:LITERAL id="TreeView" runat="server" Enableview_state="false"></ASP:LITERAL>
 <asp:TextBox id="txtsel" runat="server"></asp:TextBox>
--------
Code Behind the Page: GTier.ascx.vb is:
-------
Public Sub Page_Load(sender As object, e As EventArgs)
  Dim oTree As New obout_ASPTreeView_2_NET.Tree()
  Dim html as String
 
          OTree.Add("a0", "a0_0", "ASP TreeView")
  Otree.Add("a0_0","a0_1","ASP TreeView1")
 
  oTree.FolderIcons = "/TreeIcons/Icons"
  oTree.FolderStyle = "/TreeIcons/Styles/Gray2"
     
 
  oTree.ShowIcons = True
  oTree.Width = "200px"

 
  'Write treeview to your page.
  TreeView.Text = oTree.HTML()
End Sub
-------


To the  TextBox "txtsel"  in  the UserControl,DNN prefixes the textbox "txtsel"
with "dnn_ctr364_GTier_txtsel"


The Java Script  is in the folder "/TreeIcons/Icons"
This is the line of code in the JavaScript  that passes selected tree node to the text box control 'dnn_ctr364_GTier_txtsel'
----
document.getElementById('dnn_ctr364_GTier_txtsel').value=tree_selected_id;
--
Rightnow i am hardcoding the textbox control .

Will it work if i move it to the production server?
Wouldn't dnn assign another prefix to my textbox control ?


How can i handle this situation

 
New Post
3/3/2009 1:44 AM
 

The first thing I'd ask is - Are you modifying the JS code provided with the tree control, or is this your custom JS file? If it's the JS that came with - I advice not modifying that.

First thing to be aware of is that the prefix is done to prevent same name conflicts. For example if you more than 1 module on the page with the container, and the container has a named control in it, there will be a conflict. The same goes for any controls in the module. Basically - ASP gets very unhappy if you have 2 controls named the same thing, as it can't identify which one it is. Many(all) asp frameworks prefix the control. Which is why all controls have CONTROLNAME.ClientID, it gives you the name of the control on the client side, which is what is needed by javascript. To get this into the JS, you need to do something like <%= CONTROLNAME.ClientID %> instead of the dnn...txtsel. It will replace it with that value.

The simple answers to your questions are - No it won't work. The ctr364 is the moduleID (I think) on that page, so the likelyhood of DNN assinging something else is nearly 100%.

To handle this situation - There are a few ways. The simplest, if you are writing your own javascript is to embed it in the ascx file. Using this
document.getElementById('<%= txtSel.ClientID %>')
you should be able to access the element. The constraint to this is that the txtSel.ClientID will only work in the ascx file that txtSel is defined in.

Another option is to pass in the clientID to the function you are using. I don't have the code for this off the top of my head, but you could something like
Func('<%...%>')
and have it send the clientID to the function and then the function can access the control from that.
 

There are other options, I haven't used them yet, so I can't say how well they work. Do some googleing of "ASP javascript clientID" and you'll be able to find them.

 

Hope that helps some.

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Dnn adding a prefix to textbox control id in my usercontrol. My java script is hard coded with the tDnn adding a prefix to textbox control id in my usercontrol. My java script is hard coded with the t


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