Get ClientId. Need Help. This is driving me crazy! Thank You.

M

Miguel Dias Moura

Hello,

I have been trying, for days, to retrieve a control's ClientId in a
javascript function.
I am using a master page and this is why I need to retrieve the
Control's ClientId.
The control Id is "Panel1". I placed "<%=Panel1.ClientID %>" in my HTML
code and I got "ctl00_pPanel1".

In my Javascript function I am using:

document.getElementById("<%=Panel1.ClientID %>").style.display =
"block";

This is not working. I also tried a hidden field but I wasn't able to
make this work.

I am including my Javascript code on Page_Init as follows:

' Include page's javascript file
If Not Page.ClientScript.IsClientScriptIncludeRegistered("MyCode")
Then
Page.ClientScript.RegisterClientScriptInclude("MyCode",
"/Scripts/MyCode.js")
End If

This is driving me crazy. I read some information on MSDN library but I
can't figure out what I am doing wrong.

Could someone tell me how to make this work?

I am using Asp.Net 2.0.

Thank You Very Much,
Miguel
 
K

Kalpesh

Hi Miguel,

I am not sure about what Panel gets rendered as (in HTML).
However, put an alert before changing the style

eg.
alert(document.getElementById("<%=Panel1.ClientID %>").style.display);

This will help debug javascript code related errors

HTH
Kalpesh
 

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