473,387 Members | 1,582 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,387 software developers and data experts.

FindControl in Repeater

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.
Jun 27 '08 #1
15 3877
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
>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.

Jun 27 '08 #2
There is a better way of doing this, but here is an example from some old
code of mine that you can play with. Not sure if this is EXACTLY what you
are looking for, but i've found that the FindControl ability in the
framework is spotty at best so I throw whatever dynamic controls I make into
a collection, in this case an ArrayList. Works well for what I was doing,
hopefully it points you in the right direction:
//Make an ArrayList to hold all of the dynamic controls.
ArrayList controls = new ArrayList();

//Lets make some text boxes.
int i = 0;
while (i <= 10)
{
TextBox tb = new TextBox();
tb.ID = i.ToString();

/*Do here whatever you will to render the control to the page,
etc.
*
*
*/
//Add the TextBox to your array List.
controls.Add(tb);
}

//Now just for measure if we are dependent on keeping and saving
that data through PostBacks, etc.
Session["Controls"] = (ArrayList)controls;
//Now at a later time if we want to get the data from those text
boxes
ArrayList controls2 = (ArrayList)Session["Controls"];

//Make a loop to see what we have and make a referrence to them.
foreach (Control cOUT in controls2)
{
TextBox txtOUT = (TextBox)cOUT;

//Get the data however you with such as txtOUT.Text;

}
Lucid
Phreak2000.Com
Administrator

<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
>>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.

Jun 27 '08 #3
FindControl does not search recursively.

You need to do RepeaterControl.FindControl("textbox1") instead of
Page.FindControl ("textbox1").

--
Madhur

<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
>>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.

Jun 27 '08 #4
Problem is, even the placeholder control is dynamically created so I can't
reference it in the code. Any thoughts?

"Madhur" <sd*@df.comwrote in message
news:uM**************@TK2MSFTNGP03.phx.gbl...
FindControl does not search recursively.

You need to do RepeaterControl.FindControl("textbox1") instead of
Page.FindControl ("textbox1").

--
Madhur

<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...
>Sorry, the controls are dynamically created and placed in a PlaceHolder
control. Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
>>>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.


Jun 27 '08 #5
On May 6, 2:13*pm, "Madhur" <s...@df.comwrote:
FindControl does not search recursively.

You need to do RepeaterControl.FindControl("textbox1") instead of
Page.FindControl ("textbox1").

--
Madhur

<msnews.microsoft.comwrote in message

news:Os****************@TK2MSFTNGP05.phx.gbl...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. *Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
>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.- Hide quoted text -

- Show quoted text -
Hi,
The above will not work neither, each row has its own set of controls,
you can do the above at a row level though
Jun 27 '08 #6
On May 6, 3:05*pm, <msnews.microsoft.comwrote:
Problem is, even the placeholder control is dynamically created so I can't
reference it in the code. *Any thoughts?

"Madhur" <s...@df.comwrote in message

news:uM**************@TK2MSFTNGP03.phx.gbl...
FindControl does not search recursively.
You need to do RepeaterControl.FindControl("textbox1") instead of
Page.FindControl ("textbox1").
--
Madhur
<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. *Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
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.- Hide quoted text -

- Show quoted text -
Yes,

Describe better your problem, what are you trying to do?
Why you need to have access to the other controls?
What control is raising the event that you are receiving in the code
behind?
Jun 27 '08 #7
On May 6, 1:57*pm, "Lucid" <lu...@phreak2000.comwrote:
There is a better way of doing this, but here is an example from some old
code of mine that you can play with. *Not sure if this is EXACTLY what you
are looking for, but i've found that the FindControl ability in the
framework is spotty at best so I throw whatever dynamic controls I make into
a collection, in this case an ArrayList. *Works well for what I was doing,
hopefully it points you in the right direction:

* * * * //Make an ArrayList to hold all of the dynamic controls.
* * * * ArrayList controls = new ArrayList();

* * * * //Lets make some text boxes.
* * * * int i = 0;
* * * * while (i <= 10)
* * * * {
* * * * * * TextBox tb = new TextBox();
* * * * * * tb.ID = i.ToString();

* * * * * * /*Do here whatever you will to render the control to the page,
etc.
* * * * * * **
* * * * * * **
* * * * * * **/

* * * * * * //Add the TextBox to your array List.
* * * * * * controls.Add(tb);
* * * * }

* * * * //Now just for measure if we are dependent on keeping and saving
that data through PostBacks, etc.
* * * * Session["Controls"] = (ArrayList)controls;

* * * * //Now at a later time if we want to get the data from those text
boxes
* * * * ArrayList controls2 = (ArrayList)Session["Controls"];
Hi,

And what happen if the user open two windows from the same session
(open one window from the other) ?
You have ONLY ONE list in Session, therefore both instances willl be
mixed together
Jun 27 '08 #8
The code below would actually overwrite the session variable every time its
ran, but if you dont want it to do that just throw a if session != null
fill session with arraylist else just render the controls to the page.
"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:2b**********************************@z72g2000 hsb.googlegroups.com...
On May 6, 1:57 pm, "Lucid" <lu...@phreak2000.comwrote:
There is a better way of doing this, but here is an example from some old
code of mine that you can play with. Not sure if this is EXACTLY what you
are looking for, but i've found that the FindControl ability in the
framework is spotty at best so I throw whatever dynamic controls I make
into
a collection, in this case an ArrayList. Works well for what I was doing,
hopefully it points you in the right direction:

//Make an ArrayList to hold all of the dynamic controls.
ArrayList controls = new ArrayList();

//Lets make some text boxes.
int i = 0;
while (i <= 10)
{
TextBox tb = new TextBox();
tb.ID = i.ToString();

/*Do here whatever you will to render the control to the page,
etc.
*
*
*/

//Add the TextBox to your array List.
controls.Add(tb);
}

//Now just for measure if we are dependent on keeping and saving
that data through PostBacks, etc.
Session["Controls"] = (ArrayList)controls;

//Now at a later time if we want to get the data from those text
boxes
ArrayList controls2 = (ArrayList)Session["Controls"];
Hi,

And what happen if the user open two windows from the same session
(open one window from the other) ?
You have ONLY ONE list in Session, therefore both instances willl be
mixed together

Jun 27 '08 #9
Sorry correct, if session = null... hehe.
"Lucid" <lu***@phreak2000.comwrote in message
news:A8**********************************@microsof t.com...
The code below would actually overwrite the session variable every time
its ran, but if you dont want it to do that just throw a if session !=
null fill session with arraylist else just render the controls to the
page.
"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:2b**********************************@z72g2000 hsb.googlegroups.com...
On May 6, 1:57 pm, "Lucid" <lu...@phreak2000.comwrote:
>There is a better way of doing this, but here is an example from some old
code of mine that you can play with. Not sure if this is EXACTLY what you
are looking for, but i've found that the FindControl ability in the
framework is spotty at best so I throw whatever dynamic controls I make
into
a collection, in this case an ArrayList. Works well for what I was doing,
hopefully it points you in the right direction:

//Make an ArrayList to hold all of the dynamic controls.
ArrayList controls = new ArrayList();

//Lets make some text boxes.
int i = 0;
while (i <= 10)
{
TextBox tb = new TextBox();
tb.ID = i.ToString();

/*Do here whatever you will to render the control to the page,
etc.
*
*
*/

//Add the TextBox to your array List.
controls.Add(tb);
}

//Now just for measure if we are dependent on keeping and saving
that data through PostBacks, etc.
Session["Controls"] = (ArrayList)controls;

//Now at a later time if we want to get the data from those text
boxes
ArrayList controls2 = (ArrayList)Session["Controls"];

Hi,

And what happen if the user open two windows from the same session
(open one window from the other) ?
You have ONLY ONE list in Session, therefore both instances willl be
mixed together
Jun 27 '08 #10
On May 6, 3:28*pm, "Lucid" <lu...@phreak2000.comwrote:
The code below would actually overwrite the session variable every time its
ran, but if you dont want it to do that *just throw a if session != null
fill session with arraylist else just render the controls to the page.
That was not the point I was trying to make, what if you want to do
the same in two pages at the same time?
Like editing a record in each page.

In that escenario (and using Session the way you are doing) one
instance will override the otehr isntance data.
Jun 27 '08 #11
On May 6, 3:05*pm, <msnews.microsoft.comwrote:
Problem is, even the placeholder control is dynamically created so I can't
reference it in the code. *Any thoughts?

"Madhur" <s...@df.comwrote in message

news:uM**************@TK2MSFTNGP03.phx.gbl...
FindControl does not search recursively.
You need to do RepeaterControl.FindControl("textbox1") instead of
Page.FindControl ("textbox1").
--
Madhur
<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. *Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
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.- Hide quoted text -

- Show quoted text -
Hi,

In this case first of all you need to recreate ALL the controls in
postback.
Here is a piece of code I use to create and fill a repeater in code.
There are some classes of mine that I use (cause I bind to a
collection of business objetcs) that yo will not have, but you will
get the idea of how it is done.

List<ControlCreateRepeaterItemsControls() {
List<ControlcontrolsInRow = new List<Control>();
controlsInRow.Add(new LiteralControl("<tr class=
\"RoleControlRepeaterRowCssClass\"><td align=\"right\" style=\"width:
50%\">"));
Control c = new Label();
c.ID = "RoleNameLBL";
controlsInRow.Add(c);
controlsInRow.Add(new LiteralControl("</td><td align=\"left
\" style=\"width: 50%\">"));
c = new CheckBox();
c.ID = "RoleStatusCHK";
controlsInRow.Add(c);
spanDiv = new HtmlGenericControl();
spanDiv.ID = "SpanDiv";
spanDiv.Style.Add("visibility", "hidden");
messageLBL = new Label();
messageLBL.ID = "MessageLBL";
spanDiv.Controls.Add(messageLBL);
controlsInRow.Add(spanDiv);
controlsInRow.Add(new LiteralControl("</td><td></td></
tr>"));

return controlsInRow;
}
List<ControlCreateRepeaterHeaderControls() {
List<ControlcontrolsInRow = new List<Control>();
controlsInRow.Add(new LiteralControl("<table width=\"100%
\">"));

return controlsInRow;
}
List<ControlCreateRepeaterFooterControls() {
List<ControlcontrolsInRow = new List<Control>();
controlsInRow.Add(new LiteralControl("</table>"));

return controlsInRow;
}
//The delegate declaration for the above methods
delegate List<ControlRepeaterControlCreator();
//This is the class that implement the template for each row
of the repeater
class RepeaterTemplate: ITemplate {
RepeaterControlCreator controlCreator;
public RepeaterTemplate(RepeaterControlCreator
controlCreator) {
this.controlCreator = controlCreator;
}
public void InstantiateIn(System.Web.UI.Control container)
{
foreach (Control c in controlCreator())
container.Controls.Add(c);
}
}

protected override void CreateChildControls() {
base.CreateChildControls();

roleLST = new Repeater();
roleLST.ItemDataBound += new
RepeaterItemEventHandler(RoleLST_ItemDataBound);
roleLST.HeaderTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterHeaderControl s)) ;
roleLST.ItemTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterItemsControls ));
roleLST.AlternatingItemTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterItemsControls ));
roleLST.FooterTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterFooterControl s));

Controsl.Add( roleLST);
}
protected void OkBTN_Click(object sender, EventArgs e) {
//update the status
int index = 0;
foreach (RepeaterItem rItem in roleLST.Items) {
CheckBox cb = rItem.FindControl("RoleStatusCHK") as
CheckBox;
}
Jun 27 '08 #12
Well you could always create session variables based off the pages name that
they are currently on ( basically by the file name they are currently on )
and declare your session as Session[filename+"Controls"], then do the same
in reverse when wanting to access the controls in said session. If you are
using the same page with different pass-in vairables to decide what is
dynamically created delcare the session based off of said pass in (
Session[Request.QueryString["YourPassIn"]+"Controls], and again, do the same
in reverse when wanting to access the controls in the array list.


"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:a5**********************************@24g2000h sh.googlegroups.com...
On May 6, 3:28 pm, "Lucid" <lu...@phreak2000.comwrote:
The code below would actually overwrite the session variable every time
its
ran, but if you dont want it to do that just throw a if session != null
fill session with arraylist else just render the controls to the page.
That was not the point I was trying to make, what if you want to do
the same in two pages at the same time?
Like editing a record in each page.

In that escenario (and using Session the way you are doing) one
instance will override the otehr isntance data.

Jun 27 '08 #13
On May 6, 5:05*pm, "Lucid" <lu...@phreak2000.comwrote:
Well you could always create session variables based off the pages name that
they are currently on ( basically by the file name they are currently on )
and declare your session as Session[filename+"Controls"], then do the same
in reverse when wanting to access the controls in said session.
What if it's the same page? :)

Don't get me wrong, the reason I'm being so persistent is that I found
my self in that case, and then I realized that I had no clear way of
how to store two concurrent status in session.

I haven;t solved the problem yet, in my case I could simply use the
ViewState of the page (the data amount wat not big and it was
serializable) but otherwise I would still have the issues
Jun 27 '08 #14
Like I said before if its the same page you could always use query strings
to decide what section to store the array in, thats actually in fact what I
had to do for a dynamic survey engine I wrote. One web user control that
pulled questions from the database and created dynamic textboxes for each
question. Basically I used the query string "?step=[1-10]" and for each
step I held a reference to those controls in a seperate session variable.
"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:53**********************************@z72g2000 hsb.googlegroups.com...
On May 6, 5:05 pm, "Lucid" <lu...@phreak2000.comwrote:
Well you could always create session variables based off the pages name
that
they are currently on ( basically by the file name they are currently on )
and declare your session as Session[filename+"Controls"], then do the same
in reverse when wanting to access the controls in said session.
What if it's the same page? :)

Don't get me wrong, the reason I'm being so persistent is that I found
my self in that case, and then I realized that I had no clear way of
how to store two concurrent status in session.

I haven;t solved the problem yet, in my case I could simply use the
ViewState of the page (the data amount wat not big and it was
serializable) but otherwise I would still have the issues

Jun 27 '08 #15
Hello
You mentioned about using session variable to store Repeater item values. My tasks involve exactly the same but I am not sure how to do this. Can you post some sample code?(When I click a button, its command argument will be used to render a value on the same page. this is what i'm doin right now and i need to store the button's command argument value as session).
Thank you
Any suggestions are appreciated.
VJ
Jul 31 '08 #16

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: WebMatrix | last post by:
Hello, I have a repeater control with a placeholder inside ItemTemplate. myRpt_ItemDataBound() event adds dropdown conrol (drpCntlr.ID = ControlX) to a place holder. Then on postback, I want to...
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...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...

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.