如何让动态创建的文本框的文本值 [英] how to get the text value of dynamically created textbox

查看:250
本文介绍了如何让动态创建的文本框的文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要得到我动态创建的,当我点击一个按钮,我的文本框的值

I want to get the value of my textbox that I created dynamically when I click a button

我需要做的这个事业我的文本框的值用于从数据库中检索数据。

I need to do this cause the value of my textbox is used for retrieve data from database

如何能实现我这个东西?

how could I achieved this thing??

流量按钮点击 - 创建文本框 - 按钮单击 - - 与值填充文本框获取文本框的文本

the flow is Button click - creating textbox - filling textbox with value - Button Click - Get Text of textbox

这是我的code键使文本框

here is my code to make the textbox

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    For i As Integer = 0 To 4
        textbox = New TextBox With {.ID = "TextBox" & i}
        plchld.Controls.Add(textbox)
    Next
End Sub

我已经试过这样的事情,但code没有工作

I have tried something like this but the code didn't work

Protected Sub OkButton_Click(sender As Object, e As EventArgs) Handles OkButton.Click
    Dim a(5) As String
    For i As Integer = 0 To 4
        a(i) = CType(plchld.FindControl("Textbox" & i), TextBox).Text
    Next
End Sub

在此先感谢您的帮助。

thanks in advance for any help

编辑的答案

我已经找到解决这个的方式。我使用的Request.Form让我的文本框的值。

I've found the way to solve this. I use request.form to get the value of my textbox.

感谢任何人,参加

问候,

朱利安

推荐答案

这是我如何我的asp.net应用程序完成的。

This is how I have done in my asp.net application.

创建动态控制

TextBox txtDate = new TextBox();
txtDate.EnableViewState = true;
txtDate.ID = "PreixValue" + 1;
txtDate.Text = "07 Feb 2014"
pnl.controls.add(txtdate); 

要从该文本框检索值

DateTime datefrom = DateTime.Now ;

                for (int cnt = 0; cnt < Request.Form.Count; cnt++)
                {
                    if (Request.Form.AllKeys[cnt].Contains("Prefixvalue"))
                    {
                        int ParamStartPoint = Request.Form.AllKeys[cnt].IndexOf("Prefix") + 4;
                        int ParamNameLength = Request.Form.AllKeys[cnt].Length - ParamStartPoint;

                        string[] ControlName = Request.Form.AllKeys[cnt].Substring(ParamStartPoint, ParamNameLength).Split('$');

                                if (ControlName[0] == "Date From")
                                {

                    datefrom = DateTime.Parse(Request.Form[cnt]); 
                    //datefrom has value now
                                }
    }
}

这是我如何我的web应用程序做的,但可能有其他的方式实现这一目标。

This is how I have done in my web application, but there may be other ways achieve this.

基本上当您创建表单动态控制,这将是可以通过的Request.Form。

basically when you create Dynamic control in webform this will be available through Request.Form.

希望这可以帮助你。

这篇关于如何让动态创建的文本框的文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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