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

Home Posts Topics Members FAQ

FindControl and repeater

This is just a rephrased version of a question I posted earlier. I think I'm
closer now, so it seemed worthy of a new (more specific) post.

In my repeater I'm dynamically creating text boxes, so at compile time I
don't know what text boxes are going to be present at run time. This is
where it seems the FindControl method would be come into play. I loop
through a list of control (all textboxes) names I created on page load and
see if they exist. Unfortunately, even though I see them on the page,
FindControl doesn't come back with anything. I'm guessing it's how I'm
implementing it. Here's some code:

For Each drfields In dtVFields.Rows

Dim strField As String = drfields.Item("Field")

Dim tb As Control = rptVerify.FindControl("txt" & strField)

If Not IsNothing(tb) Then

txtInput = tb.Text

End If

-----------------------

In my test scenario I know I created a textbox with an ID of txtbirth_date
inside the repeater rptVerify, but the code above returns nothing for tb. If
I load the page in a browser and view source, I see my textbox, and it's
id="rptVerify__ctl0_txtbirth_date". So the parent control name is in there,
the id I was expecting is in there, and some other stuff is in there. I
don't even know if that's really relevant. Anyone got any hints to make this
work? Thanks!

Matt
Nov 18 '05 #1
4 4117
Sorry I don't have time today to go back and forth with you to get further
clarification of what you are doing - so I'll go off of what my best guess
is:

I have done apparently similar things but with a DataList (rather than with
a Repeater), and this is what worked for me.

1. I included a <table> in the ItemTemplate (which gets repeated for each
DataRow in the DataTable to which the control is bound at runtime.
2. Within the <table> I have a number of controls all arranged nicely of
course - one of which is a textbox (presumably similary to what you are
doing). Look at the HTML closely:
<asp:TextBox id="txtSequence" style="text-align:'center';" Width="35px"
MaxLength="4" Text='<%# (DataBinder.Eval(Container.DataItem,
"SequenceInCatalog")) %>' runat="server"></asp:TextBox>

Notice this part of the above line:
Text='<%# (DataBinder.Eval(Container.DataItem, "SequenceInCatalog")) %>'

This causes the textbox to get populated at runtime.

So this is what populates the textboxes in my DataList at runtime (and no,
you don't have to know what the names of the textboxes are ahead of time, or
find them, or anything else), and the number of textboxes is determined by
the number of DataRows in the DataTable to which the DataList is bound.

3. Then, when it's time to read the values of the textboxes during a
PostBack (to get the user's newly entered values), I loop through the
Request.Form collection which has everything within the <form> tags in your
aspx page as it was submitted (more than you'll want); and parse out the
control names to find the textboxes and their values.

Perhaps this is all totally off base (I suspect it may be), but I hope it
gives you some ideas for how to proceed.

I'd be interested in knowing why you cannot know the names of your textboxes
ahead of time (apparently they come in from Web.config?). It seems like that
one fact is hanging you up because the Repeater takes the name you supply
and modifies it in order to provide uniqueness when more than one instance
if the control gets rendered. Perhaps you can tell us why you don't bind
your control and prefer instead to loop through the DataTable manually (as
opposed to binding it to the Repeater).

HTH

DK


"MattB" <so********@yahoo.com> wrote in message
news:c5************@ID-86156.news.uni-berlin.de...
This is just a rephrased version of a question I posted earlier. I think I'm closer now, so it seemed worthy of a new (more specific) post.

In my repeater I'm dynamically creating text boxes, so at compile time I
don't know what text boxes are going to be present at run time. This is
where it seems the FindControl method would be come into play. I loop
through a list of control (all textboxes) names I created on page load and
see if they exist. Unfortunately, even though I see them on the page,
FindControl doesn't come back with anything. I'm guessing it's how I'm
implementing it. Here's some code:

For Each drfields In dtVFields.Rows

Dim strField As String = drfields.Item("Field")

Dim tb As Control = rptVerify.FindControl("txt" & strField)

If Not IsNothing(tb) Then

txtInput = tb.Text

End If

-----------------------

In my test scenario I know I created a textbox with an ID of txtbirth_date
inside the repeater rptVerify, but the code above returns nothing for tb. If I load the page in a browser and view source, I see my textbox, and it's
id="rptVerify__ctl0_txtbirth_date". So the parent control name is in there, the id I was expecting is in there, and some other stuff is in there. I
don't even know if that's really relevant. Anyone got any hints to make this work? Thanks!

Matt

Nov 18 '05 #2
Thanks, I'll see what I can come up with based on your information.

To answer your question: This web application is slated to be distributed to
clients so they can web-enable a legacy application without the client
having to do much programming. This particular issue stems from the ability
for our clients to have their customers look up their own records on the web
to make updates to their personal information. Different clients like to use
different pieces of information for a web visitor to confirm they are who
they say they are. So I'm trying to make it so our clients only have to list
a field (or fields) from the guest table of the underlaying db in web.config
and that/those fields will be used to generate prompts for the web visitor
to verify themselves. Then, at runtime the repeater generates text boxes
based on what field names are in the web.config. So AFIK, I won;t know the
names of the text boxes util the app is running and has dynamically created
them.

I maybe taking an awkward approach, as I'm relativley new to asp.net. If you
or anyone else see a fatal flaw in my approach, please let me know. I really
appreciate all the help so far.

An earlier version of this application was written in something called
West-Wind Web Connect (VFP/Web dev environment). That environment had a very
handy method call IsFormVar() that filled this need very well. I'm just
trying to replicate that behavior in asp.net.

Matt

David Krussow wrote:
<snip helpful info>

I'd be interested in knowing why you cannot know the names of your
textboxes ahead of time (apparently they come in from Web.config?).
It seems like that one fact is hanging you up because the Repeater
takes the name you supply and modifies it in order to provide
uniqueness when more than one instance if the control gets rendered.
Perhaps you can tell us why you don't bind your control and prefer
instead to loop through the DataTable manually (as opposed to binding
it to the Repeater).

HTH

DK


"MattB" <so********@yahoo.com> wrote in message
news:c5************@ID-86156.news.uni-berlin.de...
This is just a rephrased version of a question I posted earlier. I
think I'm closer now, so it seemed worthy of a new (more specific)
post.

In my repeater I'm dynamically creating text boxes, so at compile
time I don't know what text boxes are going to be present at run
time. This is where it seems the FindControl method would be come
into play. I loop through a list of control (all textboxes) names I
created on page load and see if they exist. Unfortunately, even
though I see them on the page, FindControl doesn't come back with
anything. I'm guessing it's how I'm implementing it. Here's some
code:

For Each drfields In dtVFields.Rows

Dim strField As String = drfields.Item("Field")

Dim tb As Control = rptVerify.FindControl("txt" & strField)

If Not IsNothing(tb) Then

txtInput = tb.Text

End If

-----------------------

In my test scenario I know I created a textbox with an ID of
txtbirth_date inside the repeater rptVerify, but the code above
returns nothing for tb. If I load the page in a browser and view
source, I see my textbox, and it's
id="rptVerify__ctl0_txtbirth_date". So the parent control name is in
there, the id I was expecting is in there, and some other stuff is
in there. I don't even know if that's really relevant. Anyone got
any hints to make this work? Thanks!

Matt


Nov 18 '05 #3
Some thoughts on your explanations (with the intent to simplify the problem
before solving it):

First, don't try to model the existing system in terms of implementation;
providing the same functionality to your users in ASP.NET may be much easier
than how it was implemented in that earlier product. Same functionality,
totally different/simpler implementation.
Different clients like to use different pieces of information...<<<
An important distinction to be made in order to solve this problem is
between the "different pieces of information" and textboxes.
The "different pieces of information" ultimately correspond to differen
columns ("fields") in a database. The textboxes can be used to display that
information. It's bad practice to tie these two things together via a naming
convention (i.e., do not do this: have a column in the database named "age"
and a textbox named "age" such that if you change the name of the textbox,
the app breaks and cannot display age from the database).
... I'm trying to make it so our clients only have to list
a field (or fields) from the guest table of the underlaying db in web.config
and that/those fields will be used to generate prompts for the web visitor
to verify themselves. <<<

Your clients don't care about the actual name of the text box(es) - so you
are free to name them whatever you want (textBox1, textBox2), and arrange
them in a table that appears in the <ItemTemplate> of a DataList like I
showed you in my previous post. ASP.NET and HTML for all that matters does
care about the names - so you can make your life easier by NOT trying to
name the controls at runtime. It can be done, but it makes things
difficult - and unnecessarily so in your case because your clients don't
need to know or care about the actual control name.

What your clients apparently do care about is the name of a column ("field")
in a database (as may be listed in your Web.config). What you can do is let
the users choose the datase columns they do want from a list (which is
populated from Web.config or from querying the database for a valid list of
column names), then based on the columns the users selected, display/collect
information in the textboxes which serve a generic data displaying/gathering
role.

What you would to is something like this:
1. Show an aspx page that lets the users choose from a list the possible
database columns they want to use for user authentication (populated from
your Web.config - but ideally from a database.

2. Dynamically build an SQL statement based on the users selection(s) from
the list.

3. Populate an ADO.NET DataSet or DataTable by using the dynamic SQL
statement.

4. Bind the DataSet or DataTable to your DataList control (like described in
my previous post). This is where you have the textboxes populated by
whatever columns exist in the DataSet/DataTable. You can bind by name or by
ordinal position in the Columns collection. Binding by ordinal gets you away
from having to know the column name ahead of time.

You'll want to include in the SQL statement, DataSet, and DataList the
ability to populate label controls that will describe the contents of the
textbox. The textboxes can apparently contain different types of
information, so it would be important to tell the users which textboxes are
showing which columns. You can display the column name in a label next to
the textbox that shows the value of the column for the current row.

I hope this helps.

DK

"MattB" <so********@yahoo.com> wrote in message
news:c5************@ID-86156.news.uni-berlin.de... Thanks, I'll see what I can come up with based on your information.

To answer your question: This web application is slated to be distributed to clients so they can web-enable a legacy application without the client
having to do much programming. This particular issue stems from the ability for our clients to have their customers look up their own records on the web to make updates to their personal information. Different clients like to use different pieces of information for a web visitor to confirm they are who
they say they are. So I'm trying to make it so our clients only have to list a field (or fields) from the guest table of the underlaying db in web.config and that/those fields will be used to generate prompts for the web visitor
to verify themselves. Then, at runtime the repeater generates text boxes
based on what field names are in the web.config. So AFIK, I won;t know the
names of the text boxes util the app is running and has dynamically created them.

I maybe taking an awkward approach, as I'm relativley new to asp.net. If you or anyone else see a fatal flaw in my approach, please let me know. I really appreciate all the help so far.

An earlier version of this application was written in something called
West-Wind Web Connect (VFP/Web dev environment). That environment had a very handy method call IsFormVar() that filled this need very well. I'm just
trying to replicate that behavior in asp.net.

Matt

David Krussow wrote:
<snip helpful info>

I'd be interested in knowing why you cannot know the names of your
textboxes ahead of time (apparently they come in from Web.config?).
It seems like that one fact is hanging you up because the Repeater
takes the name you supply and modifies it in order to provide
uniqueness when more than one instance if the control gets rendered.
Perhaps you can tell us why you don't bind your control and prefer
instead to loop through the DataTable manually (as opposed to binding
it to the Repeater).

HTH

DK


"MattB" <so********@yahoo.com> wrote in message
news:c5************@ID-86156.news.uni-berlin.de...
This is just a rephrased version of a question I posted earlier. I
think I'm closer now, so it seemed worthy of a new (more specific)
post.

In my repeater I'm dynamically creating text boxes, so at compile
time I don't know what text boxes are going to be present at run
time. This is where it seems the FindControl method would be come
into play. I loop through a list of control (all textboxes) names I
created on page load and see if they exist. Unfortunately, even
though I see them on the page, FindControl doesn't come back with
anything. I'm guessing it's how I'm implementing it. Here's some
code:

For Each drfields In dtVFields.Rows

Dim strField As String = drfields.Item("Field")

Dim tb As Control = rptVerify.FindControl("txt" & strField)

If Not IsNothing(tb) Then

txtInput = tb.Text

End If

-----------------------

In my test scenario I know I created a textbox with an ID of
txtbirth_date inside the repeater rptVerify, but the code above
returns nothing for tb. If I load the page in a browser and view
source, I see my textbox, and it's
id="rptVerify__ctl0_txtbirth_date". So the parent control name is in
there, the id I was expecting is in there, and some other stuff is
in there. I don't even know if that's really relevant. Anyone got
any hints to make this work? Thanks!

Matt


Nov 18 '05 #4
That's some good info. I have all of this working except my comparison (if
text entered matches db) because I'm trying to resolve names. Your point
about ordinal position was one thing I didn't realize I could do, so I think
that's the missing link here. Thanks for taking the time to explain this.

Matt

David Krussow wrote:
Some thoughts on your explanations (with the intent to simplify the
problem before solving it):

First, don't try to model the existing system in terms of
implementation; providing the same functionality to your users in
ASP.NET may be much easier than how it was implemented in that
earlier product. Same functionality, totally different/simpler
implementation.
Different clients like to use different pieces of information...<<<
An important distinction to be made in order to solve this problem is
between the "different pieces of information" and textboxes.
The "different pieces of information" ultimately correspond to
differen columns ("fields") in a database. The textboxes can be used
to display that information. It's bad practice to tie these two
things together via a naming convention (i.e., do not do this: have a
column in the database named "age" and a textbox named "age" such
that if you change the name of the textbox, the app breaks and cannot
display age from the database).
... I'm trying to make it so our clients only have to list

a field (or fields) from the guest table of the underlaying db in
web.config and that/those fields will be used to generate prompts for
the web visitor to verify themselves. <<<

Your clients don't care about the actual name of the text box(es) -
so you are free to name them whatever you want (textBox1, textBox2),
and arrange them in a table that appears in the <ItemTemplate> of a
DataList like I showed you in my previous post. ASP.NET and HTML for
all that matters does care about the names - so you can make your
life easier by NOT trying to name the controls at runtime. It can be
done, but it makes things
difficult - and unnecessarily so in your case because your clients
don't need to know or care about the actual control name.

What your clients apparently do care about is the name of a column
("field") in a database (as may be listed in your Web.config). What
you can do is let the users choose the datase columns they do want
from a list (which is populated from Web.config or from querying the
database for a valid list of column names), then based on the columns
the users selected, display/collect information in the textboxes
which serve a generic data displaying/gathering role.

What you would to is something like this:
1. Show an aspx page that lets the users choose from a list the
possible database columns they want to use for user authentication
(populated from your Web.config - but ideally from a database.

2. Dynamically build an SQL statement based on the users selection(s)
from the list.

3. Populate an ADO.NET DataSet or DataTable by using the dynamic SQL
statement.

4. Bind the DataSet or DataTable to your DataList control (like
described in my previous post). This is where you have the textboxes
populated by whatever columns exist in the DataSet/DataTable. You can
bind by name or by ordinal position in the Columns collection.
Binding by ordinal gets you away from having to know the column name
ahead of time.

You'll want to include in the SQL statement, DataSet, and DataList the
ability to populate label controls that will describe the contents of
the textbox. The textboxes can apparently contain different types of
information, so it would be important to tell the users which
textboxes are showing which columns. You can display the column name
in a label next to the textbox that shows the value of the column for
the current row.

I hope this helps.

DK

"MattB" <so********@yahoo.com> wrote in message
news:c5************@ID-86156.news.uni-berlin.de...
Thanks, I'll see what I can come up with based on your information.

To answer your question: This web application is slated to be
distributed to clients so they can web-enable a legacy application
without the client having to do much programming. This particular
issue stems from the ability for our clients to have their customers
look up their own records on the web to make updates to their
personal information. Different clients like to use different pieces
of information for a web visitor to confirm they are who they say
they are. So I'm trying to make it so our clients only have to list
a field (or fields) from the guest table of the underlaying db in
web.config and that/those fields will be used to generate prompts
for the web visitor to verify themselves. Then, at runtime the
repeater generates text boxes based on what field names are in the
web.config. So AFIK, I won;t know the names of the text boxes util
the app is running and has dynamically created them.

I maybe taking an awkward approach, as I'm relativley new to
asp.net. If you or anyone else see a fatal flaw in my approach,
please let me know. I really appreciate all the help so far.

An earlier version of this application was written in something
called West-Wind Web Connect (VFP/Web dev environment). That
environment had a very handy method call IsFormVar() that filled
this need very well. I'm just trying to replicate that behavior in
asp.net.

Matt

David Krussow wrote:
<snip helpful info>

I'd be interested in knowing why you cannot know the names of your
textboxes ahead of time (apparently they come in from Web.config?).
It seems like that one fact is hanging you up because the Repeater
takes the name you supply and modifies it in order to provide
uniqueness when more than one instance if the control gets rendered.
Perhaps you can tell us why you don't bind your control and prefer
instead to loop through the DataTable manually (as opposed to
binding it to the Repeater).

HTH

DK


"MattB" <so********@yahoo.com> wrote in message
news:c5************@ID-86156.news.uni-berlin.de...
This is just a rephrased version of a question I posted earlier. I
think I'm closer now, so it seemed worthy of a new (more specific)
post.

In my repeater I'm dynamically creating text boxes, so at compile
time I don't know what text boxes are going to be present at run
time. This is where it seems the FindControl method would be come
into play. I loop through a list of control (all textboxes) names I
created on page load and see if they exist. Unfortunately, even
though I see them on the page, FindControl doesn't come back with
anything. I'm guessing it's how I'm implementing it. Here's some
code:

For Each drfields In dtVFields.Rows

Dim strField As String = drfields.Item("Field")

Dim tb As Control = rptVerify.FindControl("txt" & strField)

If Not IsNothing(tb) Then

txtInput = tb.Text

End If

-----------------------

In my test scenario I know I created a textbox with an ID of
txtbirth_date inside the repeater rptVerify, but the code above
returns nothing for tb. If I load the page in a browser and view
source, I see my textbox, and it's
id="rptVerify__ctl0_txtbirth_date". So the parent control name is
in there, the id I was expecting is in there, and some other stuff
is in there. I don't even know if that's really relevant. Anyone
got any hints to make this work? Thanks!

Matt


Nov 18 '05 #5

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

Similar topics

4
by: MattB | last post by:
This is just a rephrased version of a question I posted earlier. I think I'm closer now, so it seemed worthy of a new (more specific) post. In my repeater I'm dynamically creating text boxes, so...
3
by: Martin | last post by:
Hi, I have a very frustrating problem that I have researched for countless hours to no avail. There are many posts asking very similar things, however none usefull in my situation. I am using VS...
1
by: HockeyFan | last post by:
I have the following string from one of the controls, inside gridview, inside a control, inside a repeater item. rptBorrower_ctl00_ctlAuthorizedSigners_gvAuthorizedSigners_ctl04_ The control was...
5
by: John Kotuby | last post by:
Hi all, After more than a year programming with ASP.NET 2.0 and VB I am still finding it difficult to leave some habits from classic ASP behind. this is particularly true with cross-page posting....
5
by: pechar | last post by:
Hi all, First and foremost I am a person who hates to add C# code to aspx file and prefer using only codebehind. I know there are certain scenarios where it is impossible to evade but thats...
15
by: | last post by:
I dynamically create controls (textboxes) in a repeater control. I know their names (eg. TextBox1). How do I find the text of TextBox1 in the Form? FindControl does not seem to work.
1
by: MDS1 | last post by:
Hi, I have a html table inside a repeater control. There is a row in the table that I need to toggle the visibility of. I have set the <tr> to runat="server" and have given it the ID of...
2
by: Jeff | last post by:
hi asp.net 2.0 I'm having trouble with findcontrol. The problem is in the code below. The is that this line don't work: label = (Label)e.Item.FindControl("lblKode"); label has a NULL value...
9
by: AAaron123 | last post by:
I'm this far in determining the correct code to find a textbox I need to set. ...
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.