Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using page1 and page2 in asp.net c#. In Page1 , i am having gridview with checkboxes and normal few text boxs. Page2 is the output page. I am facing the below issues.
1. In page1 gridview will bind few records with checkboxes. User will select some records through checkboxes in gridview and will enter some data in normal text boxes.
If I click the next button, it will opens the Page2. Now if i click the back button in Page2, it will loads the Page1. My requirement is, if i click the back button in page2, i need to get Page1 with entered text in text boxes and checked records in the gridview earlier which i selected..
I dont want to reload the fresh page once again when i enterd back button in page2. I am loosing all the data in page1 if i comes back. I request please help for the solution.

Thanks
Mahesh
Posted

HI use sessions variable to store the control values
 
Share this answer
 
v2
XML
Hi Use the below Code on Page1

protected void Page_Load(object sender, EventArgs e)
{
  if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
  {
      TextBox1.Text = Session["Rajesh"].ToString();
  }
}
protected void ButtonNext_Click(object sender, EventArgs e)
{
     Session["Rajesh"] = TextBox1.Text;

     Response.Redirect("default2.aspx");
}

On Page2 button ButtonPrevious tag  use PostBackUrl property to go back to previous page
<pre lang="xml"><asp:Button ID="ButtonPrious" runat="server" onclick="Button1_Click"  PostBackUrl="~/Default.aspx"  Text="Button" />



This will help you to maintain the previuos page state of the control

Please dont forget to vote if it is helped to you
 
Share this answer
 
Comments
raju melveetilpurayil 7-Oct-10 18:51pm    
you can edit your previous post ;) no need to post new
raju melveetilpurayil 7-Oct-10 18:53pm    
always check session is null before access session.

if(Session["Rajesh"]!=null){
TextBox1.Text = Session["Rajesh"].ToString();
}
Rajesh Sajjanar 8-Oct-10 10:49am    
Checking session null value I am very much aware , the best coding practice should be followed from coder/ question poster. The intent of the answer is for the posted question, reconsider your vote

What is the reason ? is the code not work for the previous button click, page1 details are maintained ?
Hi Rajesh,
I did as your suggestion, in all controls and page i made as View state = "True" . Even though, the page is getting refresh. i am not getting the actual solution. Instead of using session, i am expecting other solution. Because, in the page there are lots of controls and grids are existing. It is very difficult to maintain the all controls data in session.
I am expecting selected and entered data in Page1 to Page2, if i come back to page1, the same i need to see all the controls whatever i entered and selected in the grid. I request please help out for the solution.
Thanks
Mahesh.
 
Share this answer
 
Comments
Rajesh Sajjanar 8-Oct-10 10:50am    
Did you try my Answer 3 ? that will work perfectly

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