質問

I am doing a project of university. I want to create textboxes at run time and set their location one after another. Can anybody help me in setting their size and pattern?

namespace DynamicControl
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int rowCount = 10;

            //Create the textboxes 
            for (int i = 0; i < rowCount; i++)
            {
                TextBox TxtBoxMessage = new TextBox();
                TxtBoxMessage.ID = "TextBoxMessage" + i.ToString();

                //Add  textboxes to the Panel.
                Panel1.Controls.Add(TxtBoxMessage);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }
    }
}
役に立ちましたか?

解決

You need to create the controls int the Page_Init event, not Page_Load.

See HOW TO: Dynamically Create Controls in ASP.NET

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top