Problem with Aps.Net 2.0 Master Page. ID's?

M

Miguel Dias Moura

Hello,

I am using a Master Page (MyMaster) with a Content Place Holder
(ID="ContentPlaceHolder1").
In MyPage.aspx I inserted an Asp:panel (ID="Panel1") inside
ContentPlaceHolder1.

I am having problems using javascript functions with Panel1.
For example, my javascript functions say they can't find an element with
ID="Panel1" in my page.

The same happens when I use CSS styles like "#Panel1 {...}".

I believe the problem is that when MyPage.aspx runs Panel1's ID becomes
"ctl00_ContentPlaceHolder1_Panel1".
I saw the Panel1's ID in IE and Firefox "View Source" option.

How can I solve this so I can use my javascript functions and CSS "#..."
type styles?

Thank You,
Miguel
 
T

Tim_Mac

hi miguel ,
i also encountered this issue. as long as you are dealing with
controls that always have the same ID, you can just refer to the full
name "ctl00_ContentPlaceHolder1_Panel1" in your javascript.

or you could add server code to specify the javascript
attributes/values accessing the Control.UniqueID property which should
contain the fully qualified control name.

to overcome the CSS issue, i would use class names instead of IDs.

let me know if this doesn't solve your problem.
tim
 
J

Jacob

Master pages alter the ID's. You can reference them using ClientID,
which gets you the ID as it is rendered on the client.

For CSS you can use CSS classes, they don't get altered. If the CSS is
defined on the page you might be able to inject the ClientID using <%=
Panel1.ClientID %> although I have never tried this.
 
M

Miguel Dias Moura

Hi,

About CSS that was exactly what I did. I am using classes.
But how to get the client id on a javascript function?

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top