0% found this document useful (0 votes)
110 views

(Single Parameter) Default - Aspx: 1) Response - Redirect

The document discusses two methods for redirecting between pages in ASP.NET - Response.Redirect and Server.Transfer. 1) Response.Redirect changes the URL in the browser and can pass query string parameters to the destination page, where they can be accessed via Request["parameter"]. 2) Server.Transfer does not change the URL in the browser. Any parameters from the source page must be accessed directly on the destination page using the same control names from the source page.

Uploaded by

santhosh1212
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

(Single Parameter) Default - Aspx: 1) Response - Redirect

The document discusses two methods for redirecting between pages in ASP.NET - Response.Redirect and Server.Transfer. 1) Response.Redirect changes the URL in the browser and can pass query string parameters to the destination page, where they can be accessed via Request["parameter"]. 2) Server.Transfer does not change the URL in the browser. Any parameters from the source page must be accessed directly on the destination page using the same control names from the source page.

Uploaded by

santhosh1212
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1) Response.

Redirect (single parameter)

Default.aspx

protected void Button1_Click(object sender, EventArgs e)


{
Response.Redirect("login.aspx?acno=" + TextBox1.Text);
}

Login.aspx

Drag and drop lable1

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


{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Request["acno"];
}
}

2. Change the code as(passing 2 values as parameter[multiple parameters] how


to handel it?)

Drag and drop TextBox2 and write following code in Button1_Click()….

Default.aspx

protected void Button1_Click(object sender, EventArgs e)


{
Response.Redirect("login.aspx?acno=" +TextBox1.Text+"&aname="+TextBox2.Text);
}
Login.aspx code is

protected void Page_Load(object sender, EventArgs e)


{
Label1.Text = Request["acno"]+"---"+Request["aname"];
}

The url is http://localhost:7813/multiformhandiling1/login.aspx?


acno=1&aname=san

(url changes in Request.Response method but doesnot changes when we use


Server.Transfer()—output is same)

2) Request.Response(url)

Eg: Response.Redirect("http://www.google.com");
Summary of Request.Response()

a)From source page:

1. Request.Response(<pagename>)
2. Request.Response(url)
3. Request.Response(qury)

Eg1:Response.Redirect("login.aspx?acno=" + TextBox1.Text);
Eg2 : Response.Redirect("login.aspx?acno="
+TextBox1.Text+"&aname="+TextBox2.Text);

b) the values coming form sourcepage is handled in distination page when


parameter is sent in the format of Request.Response(qury)using the key word
Request[“parameter name”]

[Eg1:Response.Redirect("login.aspx?acno=" + TextBox1.Text);
Eg2 : Response.Redirect("login.aspx?acno="
+TextBox1.Text+"&aname="+TextBox2.Text);]

2. Server.Transfer();

Default.aspx.cs

protected void Button1_Click(object sender, EventArgs e)


{
Server.Transfer("login.aspx", true);
//Response.Redirect("login.aspx?acno=" +
TextBox1.Text+"&aname="+TextBox2.Text);
}

Login.aspx.cs(drag and drop Lable1)

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


{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Request["TextBox1"]+"---"+Request["TextBox2"];
// Label1.Text = Request["acno"]+"---"+Request["aname"];
}
}

url: http://localhost:7813/multiformhandiling1/Default.aspx

url: http://localhost:7813/multiformhandiling1/Default.aspx

before clicking button (sending request to server’s url) the url is same of
after sending and getting response form server ie no change in url

Summary of Request.Response()

a)From source page:

1. Server.Transfer (“<pagename>”,true)

Eg: Server.Transfer("login.aspx", true);

How to handle the parameters coming form source page ?

Writ the handling code for source page in distination page as follows

Eg:
Page_Load()//login.aspx

Label1.Text = Request["TextBox1"]+"---"+Request["TextBox2"];

TextBox1 and TextBox2 are the textboxes of default.aspx sourcepage utilised as


it is in distination login.aspx page

You might also like