473,473 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ClientID problem in Asp.Net 2.0

Hello,

I am having problems in accessing controls in my Asp.Net 2.0 pages.
I know Asp.Net 2.0 generates a ClientId.

In a Javascript function I tried to hide a panel as follows:

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

It is not working. I tried to check the code as follows:

function ChangePanel()
{
var PanelClientID = document.getElementById("<%=Panel1.ClientID
%>").style.display = "block";
alert("Client ID:" + PanelClientID)
}

I get Null.

If I place the code <%=Panel1.ClientID %> in my HTML code I get:

ctl00_MyContentPlaceHolder_Panel1

This was what I was expecting.

I think I am using "<%=Panel1.ClientID %>" wrong in my Javascript
function.

This is driving me crazy.

Could someone, please, help me out?

Thank You,
Miguel

Mar 16 '06 #1
4 7763
are you using GetCallbackEventReference ?

Mar 16 '06 #2
when you view source what does your javascript look like? also looking at
the source, what is the panels actual id tag?

-- bruce (sqlwork.com)
"Miguel Dias Moura" <md*REMOVE*moura@gmail*NOSPAM*.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Hello,

I am having problems in accessing controls in my Asp.Net 2.0 pages.
I know Asp.Net 2.0 generates a ClientId.

In a Javascript function I tried to hide a panel as follows:

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

It is not working. I tried to check the code as follows:

function ChangePanel()
{
var PanelClientID = document.getElementById("<%=Panel1.ClientID
%>").style.display = "block";
alert("Client ID:" + PanelClientID)
}

I get Null.

If I place the code <%=Panel1.ClientID %> in my HTML code I get:

ctl00_MyContentPlaceHolder_Panel1

This was what I was expecting.

I think I am using "<%=Panel1.ClientID %>" wrong in my Javascript
function.

This is driving me crazy.

Could someone, please, help me out?

Thank You,
Miguel

Mar 16 '06 #3
Hi,

The panel id tag is ctl00_MyContentPlaceHolder_Panel1.

When I view the source I see the include line that includes the
javascript file. I am using the following line to load the javascript
file at runtime in the Page_Init:

' Define and include javascript file
Dim name As String = "Inscricao"
Dim url As String = "Assets/Javascript/Subs.js"
Dim type As Type = Me.GetType()

' Get a ClientScriptManager reference from the Page class
Dim reference As ClientScriptManager = Page.ClientScript

' Check if the include script is already registered
If (Not reference.IsClientScriptIncludeRegistered(type, name)) Then
' Include javascript file
reference.RegisterClientScriptInclude(type, name, url)
End If

However I call the javascript function only when a dropdownlist is
changed.
I can't figure what the problem is.

Thanks,
Miguel

"Bruce Barker" <br******************@safeco.com> wrote in message
news:OQ*************@TK2MSFTNGP10.phx.gbl:
when you view source what does your javascript look like? also looking at
the source, what is the panels actual id tag?

-- bruce (sqlwork.com)
"Miguel Dias Moura" <md*REMOVE*moura@gmail*NOSPAM*.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Hello,

I am having problems in accessing controls in my Asp.Net 2.0 pages.
I know Asp.Net 2.0 generates a ClientId.

In a Javascript function I tried to hide a panel as follows:

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

It is not working. I tried to check the code as follows:

function ChangePanel()
{
var PanelClientID = document.getElementById("<%=Panel1.ClientID
%>").style.display = "block";
alert("Client ID:" + PanelClientID)
}

I get Null.

If I place the code <%=Panel1.ClientID %> in my HTML code I get:

ctl00_MyContentPlaceHolder_Panel1

This was what I was expecting.

I think I am using "<%=Panel1.ClientID %>" wrong in my Javascript
function.

This is driving me crazy.

Could someone, please, help me out?

Thank You,
Miguel


Mar 16 '06 #4
> The panel id tag is ctl00_MyContentPlaceHolder_Panel1.

When I view the source I see the include line that includes the
javascript file. I am using the following line to load the javascript
file at runtime in the Page_Init...


If the Javascript file is just included like that, then ASP.NET won't
be preprocessing it for server tags (<%...%>), as it isn't part of a
..aspx file. You probably need to include the JS code directly in the
aspx file, or set up a global variable in there that is accessed by the
JS file when it needs the clientID.

Mar 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maras | last post by:
Hello, as we know VB is not case sensivity. I have a following problem, I have to send to another server few parametrs by post or get method, one of them MUST be a "clientID", it's preety...
2
by: kw | last post by:
TextBox t=new TextBox(); Controls.Add(t); t.ID=t.ClientID; //reads: "_MyControl1__ctl16" And even in OnPreRender, I examine the Controls collection and verify that the ID of the TextBox is...
2
by: Neo Geshel | last post by:
I need to get the ClientID of a form field for some JavaScript. About 25+ web sites I visited recommend the following method for finding the client ID of a web form: Web Form -> <asp:TextBox...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
2
by: Neo Geshel | last post by:
After pouring over about a dozen sites that clearly dealt with ClientID all by itself, I came to the realization that about 2/3+ of them were doing it wrong. It is indeed impossible to grab the...
7
by: Stoyan Stratev | last post by:
I have a control whose ClientID is used in a number of Javascript routines. It turned out that the ClientID has a dash (-) in it and breaks the JS. Is there a way to change the ClientID of that...
2
by: JJ | last post by:
Hi, Can anyone advise me how is the ClientID issued? I had a suite Controls which consist of a context menu (i.e. a group of tables, rows and cells situated in a class library) and a set of...
0
by: Vikram | last post by:
is someone has faced this kind of problem... I am using clientid porperty of server control in this manner in a javascript alert('<%=txt.clientid%>') now first time it give some spaces in the...
2
by: davidr | last post by:
I'm reposting hoping to get a reply, my last one got bumped down because I posted in the late day. Hi, I have in my behind code a user control with the following in Page Load: ...
2
by: DC | last post by:
Hi, I am doing something like this in the ItemCreated event (ASP.Net 1.1): DataGridItem pagerRow = e.Item; TableCell pagerCell = pagerRow.Cells; Control addedControl = new Control();...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.