Sending out two textboxes as opposed to one dynamically

Total Post:154


 1355  View(s)
Rate this:

public partial class Testing : System.Web.UI.Page


protected void Page_Load(object sender, EventArgs e)


    // Add any controls that have been previously added dynamically

    for (int i = 0; i < TotalNumberAdded; ++i)


        AddControls(i + 1);


    // Attach the event handler to the button

    Button1.Click += new EventHandler(Button1_Click);


protected void Button1_Click(object sender, EventArgs e)


    // Increase the number added and add the new label and textbox




private void AddControls(int controlNumber)


        var newPanel = new Panel();

        var newLabel = new Label();

        var newTextbox = new TextBox();

        // textbox needs a unique id to maintain state information

        newTextbox.ID = "TextBox_" + controlNumber;

        newLabel.Text = "Nature Of Accident";

        // add the label and textbox to the panel, then add the panel to the form





    protected int TotalNumberAdded


        get { return (int)(ViewState["TotalNumberAdded"] ?? 0); }

        set { ViewState["TotalNumberAdded"] = value; }



  1. Re: Sending out two textboxes as opposed to one dynamically

    Hi Manoj, 

    Does your button have an event tied to it already in the asp page?

    Button1.Click += new EventHandler(Button1_Click);

    That seems like it could give you some problems, especially on reloads.


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.