Sunday, 12 October 2014

When I Enter Value in Home.aspx it Result will give in About.aspx(Response & Redirect).


Write a Program in ASP.NET That When I Enter Value in Home.aspx it Result will give in About.aspx(Response & Redirect).




STEPS :-


STEP:- 1  CREATE NEW PROJECT.
Go to File -> New -> Project -> Select asp.net web forms application -> Entry Application Name -> Click OK.


STEP:-2 Copy The Code And Paste These Code in Home.aspx.
  1. <div>
  2.     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  3.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  4.         <br />
  5. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  6.         <br />
  7. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  8.         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  9.         <br />
  10.         <br />
  11. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  12.         <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
  13.         <br />
  14.         <br />
  15. &nbsp;&nbsp;&nbsp;&nbsp;
  16.         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  17.         <br />

  18.     </div>




STEP:-3 Copy The Code And Paste These Code in Home.aspx.cs.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;

  7. namespace WebApplication1
  8. {
  9.     public partial class _Default : System.Web.UI.Page
  10.     {
  11.         protected void Page_Load(object sender, EventArgs e)
  12.         {

  13.         }

  14.         protected void Button1_Click(object sender, EventArgs e)
  15.         {
  16.             Label1.Text = Convert.ToString(Convert.ToInt32(TextBox1.Text) + Convert.ToInt32(TextBox2.Text));
  17.             Session["result"] = Label1.Text;
  18.             Response.Redirect("About.aspx");

  19.         }
  20.     }
  21. }




STEP:-4 Copy The Code And Paste These Code in About.aspx.
  1. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  2.    
  3.         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  4.     
  5. </asp:Content>





STEP:-5 Copy The Code And Paste These Code in About.aspx.cs.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;

  7. namespace WebApplication1
  8. {
  9.     public partial class About : System.Web.UI.Page
  10.     {
  11.         protected void Page_Load(object sender, EventArgs e)
  12.         {
  13.            
  14.             Label1.Text = Session["Result"].ToString();
  15.         }
  16.     }
  17. }

No comments:

Post a Comment