Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
below code i have to write in 2 or three lines how can i write this can any one help plzzzz..........


this is my first page....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
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)
    {
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            Response.Write("you have sucessfully registred...!!!");
        }
    }

    protected void btnsubmit_Click1(object sender, EventArgs e)
    {
        Application["DEMO_APPLICATION"] = txtname.Text;
        Application["DEMO_APPLICATION1"] = txtpwd.Text;
        Application["DEMO_APPLICATION2"] = txtpassword.Text;
        Application["DEMO_APPLICATION3"] = txtadd.Text;
        Application["DEMO_APPLICATION4"] = txtfull.Text;
        Application["DEMO_APPLICATION5"] = DropDownList1.SelectedIndex;
        Response.Redirect("default3.aspx");


    }
  }


this is my second page:-

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

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text =Application["DEMO_APPLICATION"].ToString();
        TextBox2.Text = Application["DEMO_APPLICATION1"].ToString();
        TextBox3.Text = Application["DEMO_APPLICATION2"].ToString();
        TextBox4.Text = Application["DEMO_APPLICATION3"].ToString();
        TextBox5.Text = Application["DEMO_APPLICATION4"].ToString();
        TextBox6.Text = Application["DEMO_APPLICATION5"].ToString();
    }
}
Posted
Updated 19-Feb-12 18:50pm
v3
Comments
Varun Sareen 20-Feb-12 0:52am    
why?
rockpune 20-Feb-12 0:56am    
i have to learn how to write above code in 2 or 3 lines plzzz tell me sir
BillWoodruff 20-Feb-12 0:52am    
homework ?
rockpune 20-Feb-12 0:57am    
i have to learn how to write above code in 2 or 3 lines plzzz tell me sir

1 solution

Hi,

You do not need to store Textbox value in Application variable.

PreviousPage.FindControl could be used to minimize code on Default2 page.

Required code on Default3 page.

C#
TextBox1.Text = ((TextBox) PreviousPage.FindControl("txtname")).Text;


but again in above code you need checking for txtname existance. So, its not always possible to minimize number of lines. but the important thing is the correct behavior then optimization.

Hope this will help you.

Thanks
-Amit.
 
Share this answer
 
Comments
Technoses 20-Feb-12 3:11am    
good work
AmitGajjar 20-Feb-12 3:42am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900