Solved

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

Posted on 2009-05-11
2
323 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

840 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