如何在按钮单击时动态添加文本框 [英] how to add textboxes dynamically on button click

查看:123
本文介绍了如何在按钮单击时动态添加文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按钮上添加文本框,无论何时单击按钮一次一个或两个...

i want to add textbox on button click one or two at a time on whatever times click on button ...

推荐答案

下面是您想法的示例代码。请根据您的要求优化此代码。



Below is sample code for you idea. Please refine this code according to your requirement.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ViewState["textBoxCount"] = 0;
    }

}

protected void Button1_Click(object sender, EventArgs e)
{
    int textBoxCount =(int) ViewState["textBoxCount"] ;
    textBoxCount++;
    for (var i = 0; i < textBoxCount; i++)
    {
        TextBox txt = new TextBox();
        Literal lit = new Literal();
        lit.Text = "";

        PlaceHolder1.Controls.Add(txt);
        PlaceHolder1.Controls.Add(lit);
    }
    ViewState["textBoxCount"] = textBoxCount;
}


这篇关于如何在按钮单击时动态添加文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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