从动态显示始终为null [英] From dynnamic showing always null

查看:67
本文介绍了从动态显示始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有动态控制并放在桌子上。当我使用如果conditon我得到控制名称,但我没有得到值.Below是我的代码。

 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))
{
}



您有任何想法或建议非常感谢。



提前致谢。

Shafik

解决方案

试试这个代码

  if  string  .IsNullOrEmpty(txtBD.Text)&&  string  .IsNullOrEmpty(txtED.Text)&& ddlAuditor.Items.Count >   0 ))
{
}


您需要在Page_PreInit方法中运行代码。这是你需要添加/重新添加任何动态创建的控件以使它们正常运行的地方。



在<中查看有关这些类型问题的更多信息a href =http://msdn.microsoft.com/en-us/library/ms178472.aspx>关于ASP.NET页面生命周期的MSDN文章 [ ^ ]



来自 stackoverflow。 com [asp-net-get-the-text-from-a-dynamic-inserted-textbox-return-null-all-the-tim] [ ^

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

解决方案

try this code

if (string.IsNullOrEmpty(txtBD.Text) && string.IsNullOrEmpty(txtED.Text) && ddlAuditor.Items.Count > 0))
{
}


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][^]


这篇关于从动态显示始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆