Solved

WEIRD! Javascript to get a panels id when in masterpage:  ctl00_ problem

Posted on 2009-05-11
2
322 Views
Last Modified: 2012-05-06
Hi all,
Weird weird one this.
I have a page that has a panel "PopupPanel" that i show and hide with little javascript function.
Since the panel is in a custom control in a content placeholder in a masterpage .. the id of the field changes to:
ctl00_ContentPlaceHolder1_SelectMultipleUsers1_PopupPanel

i.e.
<div id="ctl00_ContentPlaceHolder1_SelectMultipleUsers1_PopupPanel" class="PopupPanel" style="display:none;">

This is pretty annoying but I worked around it by using the created name in the javascript

var theDiv = document.getElementById("ctl00_ContentPlaceHolder1_SelectMultipleUsers1_PopupPanel");

This is all fine until i put it on a different server and for some unknow reason its changed the prefix!! Its now:
_ctl0_ContentPlaceHolder1_SelectMultipleUsers1_PopupPanel

I dont know whats different on that server but the server admin has told me they should be the same! I was never 100% happy using the full name but ah well.

So my question is:
Is there any way to specify what prefix is used with master pages / controls?

Failing that would anyone know of a better way to get the panel in javascript?
Thanks in advance
O
0
Comment
Question by:osion
2 Comments
 
LVL 15

Accepted Solution

by:
mohan_sekar earned 500 total points
ID: 24355472
Your controlname.ClientID in your javascript instead of hardcoding the control name

example: document.getElementById("<%=PopupPanel.ClientID%>")
0
 

Author Closing Comment

by:osion
ID: 31580176
wow! that was fast! thanks a million.. saved ages of time fiddling around with that!
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

832 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