Click here to Skip to main content
12,822,929 members (50,114 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi All,

I have dynamic controls and put on a table. when i am using If conditon i am getting the control name but i am not getting the value.Below is my code.
TextBox txtBD = (TextBox)_tableControls.FindControl("txtBeginDateID");
            TextBox txtED = (TextBox)_tableControls.FindControl("txtEndDateID");
            DropDownList ddlAuditor = (DropDownList)_tableControls.FindControl("ddlAuditorsID");
            if (string.IsNullOrEmpty(txtBD.Text) && string.IsNullOrEmpty(txtED.Text) && string.IsNullOrEmpty(ddlAuditor.Text))

Do you have any ideas or suggestion is higly appreciated.

Thanks in advance.
Posted 10-Jan-13 4:27am
Updated 10-Jan-13 4:30am
Zafar Sultan 10-Jan-13 9:36am
You are not getting the value. Can you explain it more? What actually is the problem?
Shafik 10-Jan-13 9:41am
When I am debuging it in If condition i am getting always Null but the controls contain values.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this code
            if (string.IsNullOrEmpty(txtBD.Text) && string.IsNullOrEmpty(txtED.Text) && ddlAuditor.Items.Count > 0))
Shafik 10-Jan-13 9:49am
Thanks for your reply. I am getting first TextBox is null rather to go further. But it has value.Thanks Again
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You need to run your code inside the Page_PreInit method. This is where you need to add / re-add any dynamically created controls in order for them to function properly.

See more information about these types of issues in the MSDN article on the ASP.NET Page Life Cycle[^]

From [asp-net-get-the-text-from-a-dynamically-inserted-textbox-return-null-all-the-tim][^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100