Sangeetha
Sangeetha

Reputation: 69

How to pass the value for one aspx to another aspx page

<form id="form1" runat="server">
<div>
    <asp:TextBox ID="txtFirstName" runat="server">
    </asp:TextBox>
    <asp:TextBox ID="txtLastName" runat="server">
    </asp:TextBox>

     <asp:Button ID="Button1" runat="server" Text="RedirectPage" PostBackUrl="~/TestAjaxControls.aspx?FirstName=txtFirstName&LastName=txtLastName"  />
</div>

</form>

I need to access the firstname & lastname value to the next page

Upvotes: 0

Views: 10970

Answers (4)

BuddhiP
BuddhiP

Reputation: 6461

You can put them in the query string.

Response.Redirect("~/nextpage.aspx?firstName=" + txtFirstName.Text + "&lastName=" + txtLastName.Text);

You will need to add validation.

I recommend avoid using the session as it could be an overkill for something like this, and if you do however, you will have to clear the session properly.

Upvotes: 0

Ioana O
Ioana O

Reputation: 197

Or you could do the redirect on button OnClick, with the parameters in QueryString like you tried:

<asp:Button ID="Button1" runat="server" Text="RedirectPage" OnClick="Redirect_Click" />

and:

protected void Redirect_Click(object sender, EventArgs e)
{
    string firstN =txtFirstName.Text;
    string lastN =txtLastName.Text;
    string redirectUrl = String.Format("~/TestAjaxControls.aspx?FirstName={0}&LastName={1}", firstN, lastN);
    Response.Redirect(redirectUrl);
}

Upvotes: 0

Vano Maisuradze
Vano Maisuradze

Reputation: 5909

You can use PreviousPage property. Or Save values into Session

PreviousPage

To find prevoius page's controls, you can use FindControl function

TextBox txtFirstName = Page.PreviousPage.FindControl("txtFirstName") as TextBox;

Session

Save control values into session:

Session["FirstName"] = txtFirstName.Text;

And from any page you can get session value:

string firstName = Session["FirstName"].ToString();

Upvotes: 2

Pratik
Pratik

Reputation: 1512

Properies from commmon code:

public class Employee
{
    string _name;

public string Name
{
get
{
    // Return the actual name if it is not null.
    return this._name ?? string.Empty;
}
set
{
    // Set the employee name field.
    this._name = value;
}
}
}

Or Use Session a very handy and easy way

Upvotes: 0

Related Questions