如何访问生成运行时的文本框的文本 [英] how can access to text of a textbox that generated runtime

查看:67
本文介绍了如何访问生成运行时的文本框的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net表单和一些在运行时在Page_Load方法中生成的文本框

i have an asp.net form and some textbox generated at runtime in Page_Load method

protected void Page_Load(object sender, EventArgs e)
     {
             GenerateControll();
     }



和generatecontoroll()方法是


and generatecontoroll() method is

  var n = (from a in db.Parameters
                             where a.fk_OrderTypeID == OrderTypeID
                             orderby a.CodeID
                             select a);
                    foreach (var coll in n)
                    {
          if (coll.fk_ParameterTypeID == 1 || coll.fk_ParameterTypeID == 6)
                        {

                           
                            Label lblKKK = new Label();
                            lblKKK.ID = "lbl" + coll.ParameterID;
                            lblKKK.CssClass = "LabelMargin";
                            lblKKK.Text = coll.ParameterTitle;

                            TextBox txtKooft = new TextBox();
                            txtKooft.ID = "txt" + coll.ParameterID;
                            txtKooft.CssClass = "inputMargin";
                            if (coll.fk_ParameterTypeID == 6)
                            {
                                txtKooft.TextMode = TextBoxMode.MultiLine;
                            }
                            
                            Session.Add(coll.ParameterID.ToString(), txtKooft);

                        
                            pnlForm.Controls.Add(lblKKK);
                            pnlForm.Controls.Add(txtKooft);

                        }
}
}





现在我的控件动态生成,我有我可以在该页按钮的OnClick方法中获取文本框的文本属性。

i在我的page_Init方法中写下代码



now my controls generated dynamically, i have a button in may page and in OnClick method of that button i want get the text property of textboxes .
i write below code in my page_Init method

if (Session["19"] != null)
         {
             TextBox t = (TextBox)Session["19"];
             string tID = t.ID;


             string lll = t.Text;
             }





会话[19]不为空,t和tID可以正确找到但是t.Text是空的,而有些文本写在这个文本框中



Session[19] is not null and t and tID can find correctly but t.Text is empty while some texts wrote in this Textbox

推荐答案





你必须找到文本框使用带有id的findcontrol在面板内部。
Hi,

you have to find the textbox inside the panel using findcontrol with its id.


这篇关于如何访问生成运行时的文本框的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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