Friday, September 23, 2011

TEXT BOX IN ASP.NET THROUGH CODING

Here is a form in which we want to display the test box on form loading.
<form id="form1" runat="server">
    <div>
       
    </div>
    </form>


In the page load method

protected void Page_Load(object sender, EventArgs e)
        {
            form1.Controls.Add(newTextBox());    //  
newTextBox() is the method who return the test box
        }

private TextBox newTextBox()
        {
            TextBox tx = new TextBox();

           
tx.ID = "TextBox1";
           
tx.Text = "some text";
           
tx.TextMode = TextBoxMode.MultiLine;
           
tx.Attributes.Add("runat", "server");
           
tx.Rows = 3;
           
tx.AutoPostBack = true;
                    
            tx.TextChanged += new EventHandler(tb_TextChanged);    // event handelar
           
            return tx;
        }


Try and enjoy

No comments:

Post a Comment