.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

passing values from page1 to page2

Posted By: pooja     Posted Date: March 30, 2010    Points:2   Category :ASP.Net
Hi frnds,


i have 2 aspx pages... page1.aspx and page2.aspx
on page1.aspx i have textbox and button and on page2.aspx i have label.


my requirement is if i enter in page1.aspx and button clicks it goes to page2.aspx and shows the value on the label


i dont want to use any statement techniques...


i used the following but iam getting error so please help me...


in Page1.aspx i have follwowing code


protected void btnnext_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}




in page2.aspx i have folloqine code


protected void Page_Load(object sender, EventArgs e)
{
TextBox txt = new TextBox();

txt = (TextBox)(PreviousPage.FindControl("txtpage1"));
lbldis.Text = txt.Text;
}

but its giviung error as "Object reference not set to an instance of an object." in page2.aspx..

please help me in debugging this.......

thanx in advance

Responses
Author: Dilip             
Posted Date: March 30, 2010     Points: 5   

Hi Pooja,

Instead of Response.redirect use Server.Transfer. It will work..You need to maintain the context when you transfer from one page to another in this case

In case Response.redirect you loose the context. Let me know if this doesn't work I will give you another solution

Regards
Dilip
Author: Naresh             
Posted Date: March 30, 2010     Points: 5   

Hi pooja,

If Ur using web application then u can use Session.

Ist Page:

Session("UserName") = textbox1.text;

2nd Page:

Label1.text= Session("UserName")


If Ur using in windows application then the coading is,

Ist Page:

Form2name frm2=new Form2name(this.textbox1.text);
frm2=show.dialog();


2nd Page:


Public form2name(string strparam)
{
initializecomponent();
this.label1.text=strparam
}


thanks
malathy.v

Thanks
Naresh
Author: Lalij Mer             
Posted Date: March 30, 2010     Points: 5   

http://www.dotnetspider.com/forum/217162-INTERACTION-IN-FORMS-USING-C.aspx

Please Check my answer if you help....
Thank You...

Lalit.
Author: Syed Shakeer Hussain             
Posted Date: March 31, 2010     Points: 5   

Hi,
Write the code as follows:-

in page2.aspx write the following code

protected void Page_Load(object sender, EventArgs e)
{
TextBox txt = new TextBox();
Page previousPage = (Page) HttpContext.Current.PreviousHandler;
TextBox previousPageControl = (TextBox) previousPage.FindControl("txtpage1");
lbldis.Text =previousPageControl.Text;

}




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend