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

findcontrol behaviour

Hi all,

When a user clicks a button controls are generated
protected void keywordsDropDownList_SelectedIndexChanged(object
sender, EventArgs e)
{
int numberOfTextBoxes =
Convert.ToInt16(keywordsDropDownList.Text);
TextBox myTextBox;

for (int i = 0; i < numberOfTextBoxes; i++)
{
myTextBox = new TextBox();
myTextBox.ID = "parameterTextBox" + Convert.ToString(i);
myTextBox.Columns = 5;
buttonPlaceHolder.Controls.Add(myTextBox);
}
addKeywordButton.Visible = true;
MultiView1.SetActiveView(KeywordView);

TextBox myTB;
myTB =
(TextBox)buttonPlaceHolder.FindControl("parameterT extBox1");
}

The FindControl finds the parameterTextBox1 and copies it to myTB
correctly.

When a user now clicks a button after he clicked the previous one I do:
protected void addKeywordButton_Click(object sender, EventArgs e)
{
TextBox myTB;
myTB =
(TextBox)buttonPlaceHolder.FindControl("parameterT extBox1");
}

Here FindControl can't find the control and myTB is null.

I really can't find the problem so any help is greatly appreciated.

best regards
Stijn

Sep 1 '06 #1
1 941

Stijn,

The problem is that ASP.NET is stateless and on each postback you need to
create the controls (or persist the controls after they are created). A
quick search turned up the following that may help you.

http://www.tgreer.com/aspnet_html_04.html

Michael

"ta******@gmail.com" wrote:
Hi all,

When a user clicks a button controls are generated
protected void keywordsDropDownList_SelectedIndexChanged(object
sender, EventArgs e)
{
int numberOfTextBoxes =
Convert.ToInt16(keywordsDropDownList.Text);
TextBox myTextBox;

for (int i = 0; i < numberOfTextBoxes; i++)
{
myTextBox = new TextBox();
myTextBox.ID = "parameterTextBox" + Convert.ToString(i);
myTextBox.Columns = 5;
buttonPlaceHolder.Controls.Add(myTextBox);
}
addKeywordButton.Visible = true;
MultiView1.SetActiveView(KeywordView);

TextBox myTB;
myTB =
(TextBox)buttonPlaceHolder.FindControl("parameterT extBox1");
}

The FindControl finds the parameterTextBox1 and copies it to myTB
correctly.

When a user now clicks a button after he clicked the previous one I do:
protected void addKeywordButton_Click(object sender, EventArgs e)
{
TextBox myTB;
myTB =
(TextBox)buttonPlaceHolder.FindControl("parameterT extBox1");
}

Here FindControl can't find the control and myTB is null.

I really can't find the problem so any help is greatly appreciated.

best regards
Stijn

Sep 1 '06 #2

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

Similar topics

1
by: James G. Beldock | last post by:
I have seen the following behavior: when issuing a Page.FindControl() for a control which exists in an item template (from within an ItemDataBound() event, for example), I get nulls back...
2
by: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server"...
2
by: encoad | last post by:
Hi everyone, I'm slowly going mad with Masterpages and the FindControl. After a couple days of figuring out how to use the FindControl command from within a Masterpage, I still can't explain...
5
by: daniel.hedz | last post by:
I am generating a usercontrol dynamically successfully, but when I try to find that usercontrol I get a type mismatch. This is what I am doing: //Loading my usercontrol...
14
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have created a UserControl ("MyUC"). I've put a bunch of instances of that control on a Page ("Defaul.aspx"). The control works fine. Now, I want to be able to use "FindControl()" from...
3
by: J055 | last post by:
Hi I can't figure out what the difference is here. Sometimes I have a simple FormView control in a page and I can use the FormView.FindControl method to get a Label or TextBox with in it during...
7
by: AAaron123 | last post by:
Me.FindControl("MissionScheduleID"), below returns null. Do you know what I'm doing wrong? Thanks ***In my .aspx file I have: asp:Content ID="Content3"...
4
by: Hillbilly | last post by:
Maybe this is or isn't some kind of bug but it sure is goofy and remains a mystery that really has me puzzled for two reasons... // goofy syntax functions as expected... Panel finalStepButton =...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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...

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.