Pages

Subscribe:

Ads 468x60px

Thursday, March 1, 2012

how to get text box value from previous page

if you want to get a text box value from a previous page ie page1.aspx to page2.aspx
here is the way to do so,

Code for page2.aspx.cs

declare Globally the number of objects you want to access from previous page
ie

private TextBox txt_1, txt_2, txt_3;


txt_1 = this.FindControl("TextBox1", PreviousPage.Controls) as TextBox;
        txt_2 = this.FindControl("TextBox2", PreviousPage.Controls) as TextBox;
        txt_3 = this.FindControl("TextBox3", PreviousPage.Controls) as TextBox;
        Label1.Text = txt_1.Text;
        Label2.Text = txt_2.Text;
        Label3.Text = txt_3.Text;


private Control FindControl(string controlID, ControlCollection controls)
    {
        foreach (Control c in controls)
        {
            if (c.ID == controlID)
                return c;
            if (c.HasControls())
            {
                Control cTmp = this.FindControl(controlID, c.Controls);

                if (cTmp != null)

                    return cTmp;
            }
        }
        return null;
    }

No comments:

Post a Comment