473,545 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to find ClientID of web form - Solution Found

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 Client ID of a form
field from within a DataGrid like this: <%= FormFieldID.Cli entID %>. At
least, not without extra work.

How did I do this? I created a new DataGrid from scratch, with a form
above it and a form inside of it. This was a page about 50 lines long -
so, very short - with no user dependencies except for the initial
loading of the DG with content from the DB.

While I was able to get the ClientID of the form that was outside of the
DG, I was unable to do so for any form fields inside of the DG using <%=
FormFieldID.Cli entID %>. Doing so threw the error.

That got me to thinking. Which, after nearly two days of rest from the
subject, was a wee bit clearer than before Sunday.

I decided to call the form field directly. I first Dim'd a name as a
textbox, and then I called the right textbox by catching it when the DG
was being created. Since it was in the footer (the footer is an "add"
row) simply calling like this:
Dim add_Date as TextBox = e.Item.Cells(1) .FindControl("a dd_Date")
was a bit difficult. Which row would be referenced? How would the script
know to look in the footer? Since the footer comes and goes (I don't
need it during an edit), looking for it would have to be conditional.

In order to catch the right row (the footer) while the DG is being
built, I added a feature to the DataGrid itself (onItemDataBoun d =
"dg_ItemDataBou nd") which calls the sub dg_ItemDataBoun d when the
DataGrid is being built.

From here, I created a Sub (Sub dg_itemDataBoun d()) in which I
contained my attempt to find the ClientID of the form field within the
footer:
If e.Item.ItemType = ListItemType.Fo oter And dg.ShowFooter = True then
Dim add_Date as TextBox = e.Item.Cells(1) .FindControl("a dd_Date")
End If
From here it was pretty easy to set up a RegisterStartup Script (inside
the IF) that made use of add_Date.Client ID. Since I had already defined
add_Date as the form field called "add_Date" in the second cell of the
footer row, the usage of add_Date.Client ID no longer threw an error.

I also had to implement this within the dg_Edit() Sub, in a slightly
different fashion, but that's because I allow rows to be edited.

***

What is really strange is the sheer number of sites that claim that
using <%= FormFieldID.Cli entID %> will actually work inside of a
DataGrid without further modification or code. It certainly didn't work
for me.

I would also like to apologize to the community at large for my hissy
fit on the weekend. It had been a very long week, this was just one of
many problems I was still trying to solve, and Juan's reply seemed to be
mocking me for my lack of progress. Normally I'm much more mild
mannered, but something in me must have snapped from all the stress.
That should not have happened.

Gomen dasai.

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 1498
On Tue, 21 Jun 2005 22:00:10 -0700, Neo Geshel wrote:
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 Client ID of a form
field from within a DataGrid like this: <%= FormFieldID.Cli entID %>. At
least, not without extra work.

How did I do this? I created a new DataGrid from scratch, with a form
above it and a form inside of it. This was a page about 50 lines long -
so, very short - with no user dependencies except for the initial
loading of the DG with content from the DB.

While I was able to get the ClientID of the form that was outside of the
DG, I was unable to do so for any form fields inside of the DG using <%=
FormFieldID.Cli entID %>. Doing so threw the error.

That got me to thinking. Which, after nearly two days of rest from the
subject, was a wee bit clearer than before Sunday.

I decided to call the form field directly. I first Dim'd a name as a
textbox, and then I called the right textbox by catching it when the DG
was being created. Since it was in the footer (the footer is an "add"
row) simply calling like this:
Dim add_Date as TextBox = e.Item.Cells(1) .FindControl("a dd_Date")
was a bit difficult. Which row would be referenced? How would the script
know to look in the footer? Since the footer comes and goes (I don't
need it during an edit), looking for it would have to be conditional.

In order to catch the right row (the footer) while the DG is being
built, I added a feature to the DataGrid itself (onItemDataBoun d =
"dg_ItemDataBou nd") which calls the sub dg_ItemDataBoun d when the
DataGrid is being built.

From here, I created a Sub (Sub dg_itemDataBoun d()) in which I
contained my attempt to find the ClientID of the form field within the
footer:
If e.Item.ItemType = ListItemType.Fo oter And dg.ShowFooter = True then
Dim add_Date as TextBox = e.Item.Cells(1) .FindControl("a dd_Date")
End If
From here it was pretty easy to set up a RegisterStartup Script (inside
the IF) that made use of add_Date.Client ID. Since I had already defined
add_Date as the form field called "add_Date" in the second cell of the
footer row, the usage of add_Date.Client ID no longer threw an error.

I also had to implement this within the dg_Edit() Sub, in a slightly
different fashion, but that's because I allow rows to be edited.

***

What is really strange is the sheer number of sites that claim that
using <%= FormFieldID.Cli entID %> will actually work inside of a
DataGrid without further modification or code. It certainly didn't work
for me.

I would also like to apologize to the community at large for my hissy
fit on the weekend. It had been a very long week, this was just one of
many problems I was still trying to solve, and Juan's reply seemed to be
mocking me for my lack of progress. Normally I'm much more mild
mannered, but something in me must have snapped from all the stress.
That should not have happened.

Gomen dasai.

TIA
...Geshel

Thanks, I learned something from your post.

Nov 19 '05 #2
Hi,

alternative:

To get the ClientID of a control contained inside the DataGrid's item you
can create a databinding expression and run it like this

<%#Container.Fi ndControl("Form Field").ClientI d%>

in the template (ClientID will be resolved every time when databinding
happens). <%=%> won't necessarily do here because they run at rendering
stage.

(I assume you use this to create js calls into/from the controls contained
in dg)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Neo Geshel" <go****@geshel. org> wrote in message
news:uu******** ******@TK2MSFTN GP10.phx.gbl...
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 Client ID of a form
field from within a DataGrid like this: <%= FormFieldID.Cli entID %>. At
least, not without extra work.

How did I do this? I created a new DataGrid from scratch, with a form
above it and a form inside of it. This was a page about 50 lines long -
so, very short - with no user dependencies except for the initial loading
of the DG with content from the DB.

While I was able to get the ClientID of the form that was outside of the
DG, I was unable to do so for any form fields inside of the DG using <%=
FormFieldID.Cli entID %>. Doing so threw the error.

That got me to thinking. Which, after nearly two days of rest from the
subject, was a wee bit clearer than before Sunday.

I decided to call the form field directly. I first Dim'd a name as a
textbox, and then I called the right textbox by catching it when the DG
was being created. Since it was in the footer (the footer is an "add" row)
simply calling like this:
Dim add_Date as TextBox = e.Item.Cells(1) .FindControl("a dd_Date")
was a bit difficult. Which row would be referenced? How would the script
know to look in the footer? Since the footer comes and goes (I don't need
it during an edit), looking for it would have to be conditional.

In order to catch the right row (the footer) while the DG is being built,
I added a feature to the DataGrid itself (onItemDataBoun d =
"dg_ItemDataBou nd") which calls the sub dg_ItemDataBoun d when the DataGrid
is being built.

From here, I created a Sub (Sub dg_itemDataBoun d()) in which I contained
my attempt to find the ClientID of the form field within the footer:
If e.Item.ItemType = ListItemType.Fo oter And dg.ShowFooter = True then
Dim add_Date as TextBox = e.Item.Cells(1) .FindControl("a dd_Date")
End If
From here it was pretty easy to set up a RegisterStartup Script (inside the
IF) that made use of add_Date.Client ID. Since I had already defined
add_Date as the form field called "add_Date" in the second cell of the
footer row, the usage of add_Date.Client ID no longer threw an error.

I also had to implement this within the dg_Edit() Sub, in a slightly
different fashion, but that's because I allow rows to be edited.

***

What is really strange is the sheer number of sites that claim that using
<%= FormFieldID.Cli entID %> will actually work inside of a DataGrid
without further modification or code. It certainly didn't work for me.

I would also like to apologize to the community at large for my hissy fit
on the weekend. It had been a very long week, this was just one of many
problems I was still trying to solve, and Juan's reply seemed to be
mocking me for my lack of progress. Normally I'm much more mild mannered,
but something in me must have snapped from all the stress. That should not
have happened.

Gomen dasai.

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 #3

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

Similar topics

1
2502
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 simple, but in VB .NET there is a property ClientID and I get an error, a conflict beetwen my clientID and ClientID of MyBase class aspx code: ****
2
1901
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 "_MyControl1__ctl16". But then, on the final HTML rendered, if you look at the page, the textbox looks like this:
2
2371
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 ID="datefield" type="hidden" Runat="Server" /> Client ID -> <%= datefield.ClientID() %> Unfortunately, this only provides the following error: ...
25
4036
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
2
383
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 Client ID of a form field from within a DataGrid like this: <%= FormFieldID.ClientID %>. At least, not without extra work. How did I do this? I...
1
1209
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); } Works great.
0
7470
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7405
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7659
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7811
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7428
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5334
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
709
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.