第一个动态文本框应出现在页面加载上 [英] First dynamic text box should appear on page load

查看:89
本文介绍了第一个动态文本框应出现在页面加载上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了一个占位符,按钮。单击按钮动态文本框正在生成。我想显示第一个动态文本框应该始终显示。然后当我点击按钮时,下一个文本框应该出现。



这里是我的代码

Hi,
I have created a placeholder, button. on clicking the button dynamic textbox is generating. i want to show the first dynamic textbox should appear always. then when i click the button the next textbox should appear.

here is my code

<pre>  protected void LinkButton1_Click(object sender, EventArgs e)
    {
        CreateDynamicControls(true);
    }
  private void CreateDynamicControls(bool incrementRowCount = false)
    {
        int rowCount = 0;

        //initialize a session.
        rowCount = Convert.ToInt32(ViewState["clicks"]);

        if (incrementRowCount)
            rowCount++;

        ViewState["clicks"] = rowCount;

        //Create the textboxes and labels each time the button is clicked.
        for (int i = 0; i < rowCount; i++)
        {
            TextBox TxtBoxU = new TextBox();
            //TextBox TxtBoxE = new TextBox();

            Label lblU = new Label();
            //Label lblE = new Label();

            TxtBoxU.ID = "TextBoxU" + i.ToString();
            //TxtBoxE.ID = "TextBoxE" + i.ToString();
            TxtBoxU.Width=900;
            

            lblU.ID = "LabelU" + i.ToString();
            //lblE.ID = "LabelE" + i.ToString();

            lblU.Text = (i + 1).ToString() + " : ";
            //lblE.Text = "E-Mail : ";

            //Add the labels and textboxes to the Panel.
            PlaceHolder1.Controls.Add(lblU);
            PlaceHolder1.Controls.Add(TxtBoxU);
            PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
            PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
        }
    }
Kindly help





我尝试了什么:





What I have tried:

</<pre><pre>  protected void LinkButton1_Click(object sender, EventArgs e)
    {
        CreateDynamicControls(true);
    }
  private void CreateDynamicControls(bool incrementRowCount = false)
    {
        int rowCount = 0;

        //initialize a session.
        rowCount = Convert.ToInt32(ViewState["clicks"]);

        if (incrementRowCount)
            rowCount++;

        ViewState["clicks"] = rowCount;

        //Create the textboxes and labels each time the button is clicked.
        for (int i = 0; i < rowCount; i++)
        {
            TextBox TxtBoxU = new TextBox();
            //TextBox TxtBoxE = new TextBox();

            Label lblU = new Label();
            //Label lblE = new Label();

            TxtBoxU.ID = "TextBoxU" + i.ToString();
            //TxtBoxE.ID = "TextBoxE" + i.ToString();
            TxtBoxU.Width=900;
            

            lblU.ID = "LabelU" + i.ToString();
            //lblE.ID = "LabelE" + i.ToString();

            lblU.Text = (i + 1).ToString() + " : ";
            //lblE.Text = "E-Mail : ";

            //Add the labels and textboxes to the Panel.
            PlaceHolder1.Controls.Add(lblU);
            PlaceHolder1.Controls.Add(TxtBoxU);
            PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
            PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
        }}

>

推荐答案

您需要将代码放在PageLoad事件中创建第一个TextBox。 />


另外我认为你的 CreateDynamicControls 一次只能创建一组textbox + label - 你要去尝试重新创建预先存在的控件,如代码当前所示
You need to put the code to create the first TextBox in the PageLoad event.

Also I think your CreateDynamicControls should only be creating one set of textbox + label at a time - you're going to try to recreate pre-existing controls as the code currently stands


这篇关于第一个动态文本框应出现在页面加载上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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