473,322 Members | 1,431 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,322 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 19 '05 #1
2 2351
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 19 '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 19 '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...
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...
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...
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.