asp.net | Response.Redirect | Server.Transfer method using c# code source

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

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

{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("we are in new page");
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "asp.net event programming";


}

protected void Button2_Click(object sender, EventArgs e)
{
//Response.Redirect("default1.aspx");
Server.Transfer("default2.aspx");
}
}
1) run this program with help of two button and one text box
2) when you will click on button 1 then message will come on text box

and if you will click on the button 2 then it will give msg on page load .

i.e "we are in new page ".
when click on button one then

TextBox1.Text = "asp.net event programming"; this will work

means "asp.net event programming"; this msg will appear in the text

box 1.

3) if you will execeute both then problem comes in

//Response.Redirect("default1.aspx"); this line.

we wrote there on page load msg will come on screen it means it
transfer same msg using Server transfer. asfter click on button 2 it will
give msg what we have seen on page load.

0 comments:

Post a Comment