 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 5th, 2011, 04:07 PM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
keep textbox values
hi
I have two webforms
webform1: http://i52.tinypic.com/vhqd6h.png
webform2: http://i53.tinypic.com/2m65w76.png
when a user fill the webform1 and get webform2( through submit )if user click return(get webform1) i want to show user the webform1 info that user filled first time.
(i want to keep webform1 info when user go to webform2 and return to webform1)
what should i do?
thanks
|
|

February 6th, 2011, 06:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You need some way to save the state of the form so you can do a server-side redirect.
For server state, you can use:
- Session state. Store the fields in the session in page 1, and reload them again when the page is requested
- Cookies - work similar to session state but are stored client side and are accessible at the server
- Save the data in the database and reload it when the page is requested again.
In other words, lots of options to choose from. You may want to Google a bit for each of these options to see their (dis)advantages.
Alternatively, you can use JavaScript's history.go(-1) to take the user back the previous page.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

February 6th, 2011, 06:23 AM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Session state
More Guidance in Session State
thanks
|
|

February 6th, 2011, 06:44 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Heuh?
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

February 6th, 2011, 06:51 AM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
more guide in writing the code
i don't know what to type in page_load of webform1
|
|

February 6th, 2011, 06:56 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did you follow my suggestion to Google a bit on ASP.NET Session state? It's quite a broad topic and a lot has been written about it. So, you're better off reading some stuff yourself so you get a good understanding of what it is and how to use it.
http://www.google.com/#sclient=psy&h...54f5edca559ee3
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

February 6th, 2011, 08:45 AM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Session state
Quote:
Originally Posted by 123mehran
hi
I have two webforms
webform1: http://i52.tinypic.com/vhqd6h.png
webform2: http://i53.tinypic.com/2m65w76.png
when a user fill the webform1 and get webform2( through submit )if user click return(get webform1) i want to show user the webform1 info that user filled first time.
(i want to keep webform1 info when user go to webform2 and return to webform1)
what should i do?
thanks
|
please help me to write the code for save webform 1 texboxes's values
i've tried but didn't get any result
thanks
Code:
Public Class webform1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Response.Redirect("Result.aspx?name=" + Name.Text + "&lastname=" + Lastname.Text + "&Idnum=" + IDNum.Text)
End Sub
End Class
|
|

February 6th, 2011, 08:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Not sure I understand what you're asking. is this code from the first page (e.g. how you pass data to the "confirm" page) or is this your attempt to pass the values back to the first page?
Either way, the idea should work. But, depending on your current setup, on Page 2 you shouldn't get the value from a TextBox but from a query string. E.g.:
Code:
Protected Sub Goback_Click(ByVal sender As Object, ByVal e As EventArgs) Handles GoBack.Click
Response.Redirect("Page1.aspx?name=" + Request.QueryString.Get("Name"))
End Sub
Then in Page1 you can try to prefill the text box from the query string:
Code:
If Not String.IsNullOrEmpty(Request.QueryString.Get("Name"))
TextBox1.Text = Request.QueryString.Get("Name")
End If
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

April 6th, 2011, 07:02 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
You can create your own collection class and store it in the session and when the page is loaded, you can check whether the session is null or not and bind the data from your session to the controls by converting it to the collection object too...
Code:
public class Person
{
public string FirstName
{get; set;}
public string LastName
{get; set;}
}
In your Page's Code Behind:
Code:
partial class Page1:Web.Form
{
public Person myPerson
{get; set;}
protected void button1_click(object sender, EventArgs e)
{
Person p=new Person();
p.FirstName=txtFirstName.Text;
p.LastName=txtLastName.Text;
Session["Person"]=p;
}
protected void Page_Load(object sender, EventArgs e)
{
if(Session["Person"]!=null)
{
myPerson=(Person)Session["Person"];
txtFirstName.Text=myPerson.FirstName;
txtLastName.Text=myPerson.LastName;
}
}
}
Happy Coding.
__________________
Thanks in advance.
Regards,
Senthil Kumar M.
Last edited by whiterainbow; April 6th, 2011 at 07:05 AM..
|
|
The Following User Says Thank You to whiterainbow For This Useful Post:
|
|
|
 |