473,378 Members | 1,416 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,378 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 2353
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); } ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.