Solved

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

Posted on 2009-05-11
2
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

695 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