Solved

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

Posted on 2009-05-11
2
320 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
Comment Utility
Your controlname.ClientID in your javascript instead of hardcoding the control name

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

Author Closing Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now