Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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.
C#
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.
Shafik
Posted
Updated 10-Jan-13 3:30am
v2
Comments
Zafar Sultan 10-Jan-13 9:36am    
You are not getting the value. Can you explain it more? What actually is the problem?
[no name] 10-Jan-13 9:41am    
When I am debuging it in If condition i am getting always Null but the controls contain values.

try this code
C#
if (string.IsNullOrEmpty(txtBD.Text) && string.IsNullOrEmpty(txtED.Text) && ddlAuditor.Items.Count > 0))
{
}
 
Share this answer
 
Comments
[no name] 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
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 stackoverflow.com [asp-net-get-the-text-from-a-dynamically-inserted-textbox-return-null-all-the-tim][^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900