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

getting dynamically created control's value as null

Dear All,
I am mess with one situation let me explain the scenario.
I am making search form where I display 15 field in checkboxlist and user select one or two or three or any no to all field. Depending on his selection (he tick the field and click filter button ) Now in filter button click I create label and dropdownlist control(populated from database) and add it to placeholder control. Now I select value and click the search button. Now in search button I need to access those control and its selected value(ie label and droplistbox ).
I have made function to create label and dropdownlistbox which is

private void createcontrols()
{
foreach (ListItem li in CheckBoxListmst.Items)
{
if (li.Selected == true)
{

//code added to fetch dropdownlist
setting = ConfigurationManager.ConnectionStrings["StyleSearchConnectionString"];
if (setting != null)
{
Code to access data for populating dropdownlistbox
try
{
// added controls
Label label = new Label();
DropDownList dropdownlist = new DropDownList();
label.ID = "label" + i.ToString();
dropdownlist.ID = "dropdownlist" + .ToString();


i++;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Items for dropdownlist


}
PlaceHolder1.Controls.Add(label);
PlaceHolder1.Controls.Add(dropdownlist);



}

catch (SqlException ex)
{

}

Now this create function I call in one in filter button click event and second as

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
createcontrols();
}

Now in seach button click event when I am trying to access
Code is

Label objlbl;
DropDownList objdrop;
objlbl = this.Page.FindControl("label1") as Label;
objdrop = this.Page.FindControl("dropdownlist1") as DropDownList;
if ((objlbl != null) && (objdrop != null))
{
cmd.Parameters.Add("@para1", SqlDbType.VarChar).Value = objlbl.Text; //Page.FindControl("label1").ToString() ;
cmd.Parameters.Add("@value1", SqlDbType.VarChar).Value = objdrop.SelectedValue;
}
I am getting objlbl and objdrop as null.


Please help


thanks
Jul 26 '07 #1
1 1734
Plater
7,872 Expert 4TB
You will need to search for them with PlaceHolder1.FindControl("label1") since they are children of PlaceHolder1.
I believe there is also an overload to .FindControl() that allows searching of children.

In the following scenario (PlaceHolder1 contains the Labels and Page contains it and mytextbox):
Page
mytextbox
PlaceHolder1
Label1
Label2
(etc)

Page.FindControl() would let you find "PlaceHolder1" and "mytextbox", but to find the labels you would need to use the overload of FindControl() to search children's children, or do the search starting from PlaceHolder1
Jul 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
3
by: Jen | last post by:
Hi I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that? ...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
5
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
1
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a...
2
by: Amelyan | last post by:
I *finally* narrowed down my problem to my custom web control. If I hookup event inside dynamically created custom web control, it doesn't get fired. However, event gets fired for any other...
4
by: Stone Chen | last post by:
Hello, I have form that uses javascript createElement to add additional input fields to it. However, my validating script will not process new input fields because it can only find the named...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
2
by: RSH | last post by:
Hi, I have a CheckBoxList that is dynamically created in the codebehind. When I click the submit button on the form I am handling the click event but I cant get at the checked values of the...
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: 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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.