Thursday, August 13, 2009

How To Create Dynamic TextBox With Event Handler

    protected void Page_Load(object sender, EventArgs e)
    {
        createTxt();
    }

    private void createTxt()
    {
       
        TextBox txt = new TextBox();
        txt.ID = "txt1";
        txt.AutoPostBack = true;
        txt.TextChanged += new EventHandler(txt_TextChanged);
        form1.Controls.Add(txt);       
    }

    void txt_TextChanged(object sender, EventArgs e)
    {
        TextBox txtBx = (TextBox)sender;
        Page.Title = txtBx.Text;
    }


No comments: