1 / 15

MIS 3200 – Unit 6.1

MIS 3200 – Unit 6.1. Moving between pages by r edirecting Moving data between pages with session variables. Page redirection. If we want to send a user to a different page, we can do this using Response.Redirect . For example:

major
Télécharger la présentation

MIS 3200 – Unit 6.1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MIS 3200 – Unit 6.1 Moving between pages by redirecting Moving data between pages with session variables

  2. Page redirection • If we want to send a user to a different page, we can do this using Response.Redirect. For example: Before a user is re-directed to a new page, we have to consider what happens to any data entered on the page and how to move that data to the new page. One way we can address this problem is by using session state and storing session variables in the session state.

  3. Session State – What is it? “ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session.” – http://msdn.microsoft.com/en-us/library/ms178581.aspx

  4. Declaring session variables • Examples of declaring session variables: notice the usage of brackets [] instead of squiggles {} or parentheses () when working with session variables

  5. Declaring session variables • Session variables are objects • i.e. they do not have a data type (e.g. decimal) • Before using they need to either be converted • Or Cast

  6. Converting session variables

  7. Casting session variables • Considered as describing an object as a web control • The Session[“lbSelectedItems”] had to be created on a previous page (similar to slide 5) before this casting example would work.

  8. Casting session variables again • Since session variable are stored as objects, they must be converted or cast before they can be used. Here is a casting example:

  9. Unit 6 L1 • Moving data between pages • Create two pages, one called lastnameU6L1_1.aspx and another called lastnameU6L1_2.aspx • Add heading Unit 6 L1 - Session Variables(page 1) and Unit 6 L1 - Read Session Variables(page 2) • On the U6L1_1.aspx page, add a TextBox and a Button • In the button click method, assign the content of the textbox to a session variable called contentsOfTextBox • Redirect the user to the 2nd page

  10. L1 #2 • On the U6L1_2.aspx page, in the Page_Load method: • Test to see if the session variable is null • If it is null, redirect the user back to the U61_1.aspx page • Otherwise, build a string and assign the string to the label (you need to add a label to this page) • Add a button on the U6L1_2.aspx page that resets the session variable (set it to null) and redirects the user back to the 1st page:

  11. L1 #3 • Add a heading to reflect this is Unit 6 L1 • Add appropriate comments to explain what the methods are doing • Create a link to your U6L1 page from your MIS3200 page and copy everything to ASPNET and submit your MIS Portfolio URL to the drop box.

  12. Time to try it out – Unit 6 L2 • Creating and reading session variables • Copy your Unit5L2.2.aspx file to your Unit 6 folder and rename it to lastnameU6L2_1.aspx and create a 2nd page called lastnameU6L2_2.aspx • Update the heading to be Unit 6 L2 – Creating Session Variables(in the 1st file) and Unit 6 L2 – Reading Session Variables(in the 2nd file) • In U6L2_2.aspx, add an empty ListBox(which will hold the selected fees that will be stored in a session variable) • Set the SelectionMode to Multiple • Set the Rows to 5

  13. L2 #2 • In the button click method of the Calculate sales tax and total create two session variables, • one will store the contents of the selected ListBox • one will store the contents of the invoice label • your existing “clean-up” code can be commented out • redirect the user to U6L2_2.aspx • In U6L2_2.aspx, • add a label above the ListBox and set the Text property to You selected the following fees: • add a label below the ListBox to hold the invoice • add a button with the Text set to Make a new selection and in the button click method, reset both session variables and redirect the user back to the 1st page

  14. L2 #3 • Test the Make a new selection functionality by trying to run the 2nd page directly from within Web Developer – this should redirect the user to the U6L2_1.aspx page (since the session variables are set to null – you will need to test the session variables in the page_load to make sure they exist and if not, send them to the U6L2_1.aspx page) • Add appropriate comments to explain what the the methods are doing • Create a link to your U6L2_1.aspx page from your MIS3200 page and copy everything to ASPNET and submit your MIS Portfolio URL to the drop box.

  15. Think About It! • Why do we need to move data between pages? • What does casting do? • How do you cast a session variable as a label?

More Related