Click here to Skip to main content
Rate this: bad
good
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.
Shafik
Posted 10-Jan-13 3:27am
Shafik487
Edited 10-Jan-13 3:30am
v2
Comments
Zafar Sultan at 10-Jan-13 9:36am
   
You are not getting the value. Can you explain it more? What actually is the problem?
Shafik at 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
good
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))
            { 
            }
  Permalink  
Comments
Shafik at 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
good
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 stackoverflow.com [asp-net-get-the-text-from-a-dynamically-inserted-textbox-return-null-all-the-tim][^]
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
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