Tuesday 15 May 2012

how to create dynamic textbox in asp.net

Adding  Dynamic Text Box 


        protected void Page_Load(object sender, EventArgs e)
        {
           //Create Textbox instance
            TextBox box = new TextBox();
            //set properties
            box.Text = "Dynamic Text Box";
            box.Width = 200;
            box.Height = 50;
            box.Font.Size = 18;
            box.ForeColor = System.Drawing.Color.Red;
            box.BackColor = System.Drawing.Color.Yellow;
//it must be added to form's control container.
            this.form1.Controls.Add(box);
        }


Static Text box With similar Properties/Attributes

<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Width="200" Height="50" Text="Static Text Box" Font-Size="X-Large" ForeColor="#CC3300" BackColor="Yellow"></asp:TextBox>
    </div>
    </form>
</body>


textbox attributes in asp.net
   or 
Dynamic CSS attributes in textbox

add new text box
<asp:TextBox ID="TextBox2" runat="server"  Text="CSS attributes demo"></asp:TextBox>


        protected void Page_Load(object sender, EventArgs e)
        {
            
            TextBox2.Style.Add("color", "RED");
            TextBox2.Style.Add("background-color", "yellow");
            TextBox2.Style.Add("width", "200");
            TextBox2.Style.Add("height", "50");
            TextBox2.Style.Add("font-size", "x-large");
            
        }

No comments:

Post a Comment