473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Trying to find ClientID of web form

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 ID="datefield" type="hidden" Runat="Server" />
Client ID -> <%= datefield.ClientID() %>

Unfortunately, this only provides the following error:

Compilation Error
Compiler Error Message: BC30451: Name 'datefield' is not declared.
Source Error:
Line 200:
Line 201:
Line 202:<%= datefield.ClientID() %>
Line 203:
Line 204:

Why does this throw an error on my page? IF this is wrong, why did the
other 25+ MVP's (who recommended this method) also get it wrong?

As a hint, here are a few URL's where it gives the exact method that
fails for me:
http://www.syncfusion.com/FAQ/aspnet/WEB_c5c.aspx (#28.10, link doesn't
work)
http://www.startvbdotnet.com/aspsite...s/default.aspx
http://www.thecodeproject.com/aspnet...in_asp_net.asp
http://youngpup.net/2004/distro (second scrollbox)
http://www.ondotnet.com/pub/a/dotnet...t&x-order=date

And perhaps the clearest example that an author claims works, but
doesn't work with me:
http://www.janetsystems.co.uk/Defaul...=72&itemid=137

Also, how does one make an <asp:TextBox /> invisible on the web page?
Using a Type="hidden" doesn't seem to do the trick (it is still visible).

TIA
....Geshel
--
************************************************** ********************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
************************************************** ********************
Nov 21 '05 #1
2 1295
First, a comment :

None of the sites you provided links for are run by MVPs.
Please don't imply that 25+ MVPs "got it wrong".

Second, I ran the exact code segment you provided

<form runat="server">
<asp:TextBox ID="datefield" type="hidden" Runat="Server" /><br/>
<%= datefield.ClientID() %>
</form>

and it runs fine inline.
The clientID for the "datefield" textbox is returned as "datefield".

re:
Also, how does one make an <asp:TextBox /> invisible on the web page?
Using a Type="hidden" doesn't seem to do the trick (it is still visible).
You're mixing HTML syntax with ASP.NET controls syntax.

If you don't want the textbox visible, use :
<asp:TextBox ID="datefield" Runat="Server" Visible="false" />


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Neo Geshel" <go****@geshel.org> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...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 ID="datefield" type="hidden" Runat="Server" />
Client ID -> <%= datefield.ClientID() %>

Unfortunately, this only provides the following error:

Compilation Error
Compiler Error Message: BC30451: Name 'datefield' is not declared.
Source Error:
Line 200:
Line 201:
Line 202:<%= datefield.ClientID() %>
Line 203:
Line 204:

Why does this throw an error on my page? IF this is wrong, why did the
other 25+ MVP's (who recommended this method) also get it wrong?

As a hint, here are a few URL's where it gives the exact method that fails for me:
http://www.syncfusion.com/FAQ/aspnet/WEB_c5c.aspx (#28.10, link doesn't work)
http://www.startvbdotnet.com/aspsite...s/default.aspx
http://www.thecodeproject.com/aspnet...in_asp_net.asp
http://youngpup.net/2004/distro (second scrollbox)
http://www.ondotnet.com/pub/a/dotnet...t&x-order=date

And perhaps the clearest example that an author claims works, but doesn't work with me:
http://www.janetsystems.co.uk/Defaul...=72&itemid=137

Also, how does one make an <asp:TextBox /> invisible on the web page?
Using a Type="hidden" doesn't seem to do the trick (it is still visible).

TIA
...Geshel

Nov 21 '05 #2
Juan T. Llibre wrote:
First, a comment :

None of the sites you provided links for are run by MVPs.
Please don't imply that 25+ MVPs "got it wrong".
Okay, so I exaggerate a little.
Second, I ran the exact code segment you provided

<form runat="server">
<asp:TextBox ID="datefield" type="hidden" Runat="Server" /><br/>
<%= datefield.ClientID() %>
</form>

and it runs fine inline.
The clientID for the "datefield" textbox is returned as "datefield".
Unfortunately, it DOES NOT work for me.

Strangely enough, "dg.clientID" *does* work, but that's because "dg" is
the ID of the DataGrid, and "dg" (which is returned) is the full
clientID that one can see in the Table that is sent to the client.

However, [controlname].ClientID *DOES NOT WORK* for anything other than
the DataGrind ID. It throws an error that crashes the page.
re:
Also, how does one make an <asp:TextBox /> invisible on the web page?
Using a Type="hidden" doesn't seem to do the trick (it is still visible).

You're mixing HTML syntax with ASP.NET controls syntax.

If you don't want the textbox visible, use :
<asp:TextBox ID="datefield" Runat="Server" Visible="false" />


Ah. Thanks. That works, but not as required. I think I'll apply a style.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espa�ol
Ven, y hablemos de ASP.NET...
======================


--
************************************************** ********************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
************************************************** ********************
Nov 21 '05 #3

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...
1
by: kpg | last post by:
Hi all, I am using the ajax.net slider control an I added a client side value changed handler like this: function pageLoad() { $find('My_SliderExtender').add_valueChanged(OnValueChange); } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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
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...

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.