Solved

How do I Save Session Variables using master pages in VS 2005?

Posted on 2007-12-07
21
3,473 Views
Last Modified: 2010-04-21
We have the skeleton of a website with one master page and various aspx forms.  The master page contains <a href> tags to navigate around the site, each of which have a bunch of textboxes and other server controls.

We need to allow the user to navigate back and forth between pages (not all will be visited), enter data, and then click a button that will fire a process that saves this data to a database consisting of multiple tables.  The best way to think of what we are looking for is the Tab Control, where data can be entered, edited, and will persist, between tabs (our pages, in this analogy) before the data is stored.

We can't use "Save" buttons on each form because we need the same GUID (uniqueidentifier) to tie tables together.

I figured on using session variables to store the data until the data was posted to the database.  If they need to go back to the page, the session variable would re-populate the form.

The problem is, after a user has entered data in one page, navigating to another page using the master page links doesn't fire off any events that I can use to store the values in session variables.  So, without having to use a temporary database of some sort, how do I get these values into these session variables?  NOTE that it is quite possible that multiple users could be using the site at the same time.

Thanks!
0
Comment
Question by:kmoloney
  • 10
  • 9
  • 2
21 Comments
 
LVL 12

Expert Comment

by:needo_jee
ID: 20426300
Saving data in seesion would be a big overhead from performance point of view. seems there will be alot of data not just few strings?
but you want to use it anyway then cache would be appropriate way to save data temporarily and get back where you need and save at the end.
whatever navigation you need to use you .. may use just one button to save data from all page .. you may maintain session between all the pages..
If all pages are in ASP.Net then would be easy as you dont need to pass all session variables across asp.net and asp pages.

thanks
0
 
LVL 12

Accepted Solution

by:
Mortaza Doulaty earned 500 total points
ID: 20427675
Have you tried asp .net ajax extension controls?

I has a very nice TabControl, you can have multiple tabs and then have your text boxes on these tabs that persist data on tab changes, finally you can have your button in the last tab to save the information.

You can also use Wizard control. It is also good for your task.
0
 
LVL 2

Author Comment

by:kmoloney
ID: 20427724
I have AJAX extensions installed, but admittedly have not played around too much with them.  Are AJAX extension controls different than just the AJAX extensions (don't see a tab control there - just pointer, timer, ScriptManager, ScriptmanagerProxy, UpdateProgress, and UpdatePanel.

Does the server need to be running any other version of IIS (or require any other additional compatibilities) to use these controls?
0
 
LVL 2

Author Comment

by:kmoloney
ID: 20427804
Needo,

Session variable impact on performance was something I had considered as a negative.  Ideally it would be best to save the data on the client machine - it's potentially a lot of data, but typically only one, or at most two, of about ten "sections" (forms / tables) would probably be filled out.  Text fields are limited to 255 chars.

I'm not sure I know exactly how to get data into and out of the cache...any tips would be appreciated.

P.S. -- I have looked at a Multiview with a bunch of different views, but that seemed to be a lot of overhead as well on the server...agreed?
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20427811
Have you installed AjaxControlToolkit?
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20427878
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20427886
0
 
LVL 12

Expert Comment

by:needo_jee
ID: 20427966
I already have posted code for Catching a DataTable and getting back from cache.
Kindly check the link given below.

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23005645.html

Thanks
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20428713
Have you tested the tab control?

You can see an online demo at:
http://asp.net/AJAX/AjaxControlToolkit/Samples/Tabs/Tabs.aspx
0
 
LVL 2

Author Comment

by:kmoloney
ID: 20432792
Will test both caching and tools.  Mortaza, still the question as to whether or not server needs to be configured specially to handle AJAX extensions...?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 2

Author Comment

by:kmoloney
ID: 20433190
Okay, a few comments after some "DEEP THOUGHT", and checking out both caching and AJAX.

Mortaza:  The Ajax Controls look really cool.  It'll probably take me a while to learn how to use them, but in this specific instance, the tab control was all I needed, and these seems to be a viable solution.  Only problem is, I still end up with a single, big bloated page, same is if I used multiview with a bunch of views.  I was thinking that individual pages would keep at least the load burden small.  Why would a tab control in AJAX with 12 tabs and a dozen or so controls on each tab be any more efficient than simply using a MultiView control with 12 Views and the same dozen or so controls per View?

Needo:  The caching solution appears to still require code that I'm not able to ever execute, because there is no event handler for navigating out of one page to another through <a href> tags in the master page to hold this code.  When loading the app, it goes to Default.aspx, which kills any current session (Session.Abandon) and navigates to the header page (Header.aspx).  When header.aspx displays, I get the following events, in the following order, before I ever even see the page:

Pre-Init
init
init complete
Pre-Load
Load
Load Complete
Pre-Render
Pre-render Complete
SaveStateComplete
Page Unload

In order for me to cache, session, or even save any of the data I might have entered in header.aspx to a database before I navigate elsewhere, I appear to need to be able to execute code.  But there is no event that fires between entering all that data in header.aspx and navigating to another page via the <a href> link in the master page -- this latter point seem to be crux of the issue; if there was such a fix, I wouldn't need a huge, burdensome page, even one with AJAX controls, and my head wouldn't be hurting so hard.

TO ALL:  For an example of my skeleton, visit http://www.moloneyonline.com/StatusChange/Header.aspx.  If also attached the master page code (COS.master) and the css (COS.css) for the master page.

I also thought about using button controls, instead of <a href> links, in the master page.  Unlike the <a href> links, the button controls would give me a chance to capture the data.  In theory, I could somehow (a) determine what the active page was, and (b) based on that, loop through the controls to save them to the appropriate session variables or temporary tables in the database.  

The difficulties are that (a) I can't seem to figure out how to determine what the current form is when I click on a button in the master page; (b) I assume it involves a bunch of coding for "FindControl" and "Ctypes" for every single control on the form; and (c) button controls are awkward, and I'd prefer not to use them if I can avoid it.

So is it possible to create an event handler that fires when I click on one of the master page's links?

Thanks for your help and patience.  I've been developing in both Web Forms and Windows Forms, and the switch between the two is making it difficult to remember what I can and can't do with one or the other.

Gracias..



The Master Page Code:
 

<%@ Master Language="VB" CodeFile="COS.master.vb" Inherits="COS" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

    <link href="COS.css" rel="stylesheet" type="text/css" />

</head>

<body>

    <form id="form1" runat="server">
 

    <div id="header">

    <h1>Online Change of Status Form</h1>

    </div>

    

    <!--Content Tag-->

    <div id="content">

    

        <!--Left Banner Tag-->

        <div id="leftbanner">

            <a href=Header.aspx>Header Info</a><br /><br />

            <a href=Personal.aspx>Personal Changes</a><br /><br />

            <a href=Transfer.aspx>Transfer</a><br /><br />

            <a href=Splits.aspx>Split Jobs</a><br /><br />

            <a href=Status.aspx>Part/Full Time</a><br /><br />

            <a href=PayAdjust.aspx>Pay Adjustment</a><br /><br />

            <a href=Withholding.aspx>Change Withholding</a><br /><br />

            <a href=Benefits.aspx>Change Benefits</a><br /><br />

            <a href=LOA.aspx>Leave of Absence</a><br /><br />

            <a href=EmploymentChange.aspx>Change in Employment</a><br /><br />

            <a href=SpecialInstructions.aspx>Special Instructions</a></div>

        

        <!--main tag-->

        <div id="main">

    

        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

        </asp:contentplaceholder>

        

        </div> <!--End of main tag-->

    </div> <!--End of content tag-->

    </form>

</body>

</html>
 

and the CSS:
 

body 

{

	background-color: White;

	font-family:Arial,Sans-Serif;

	margin:0;

	

}
 

#header 

{

	position: relative;

	top:0;

	left:0;

	text-align:center;

	padding:10px;

	border-bottom:solid 1px black;

	

}
 

#content

{

	position:relative;

}
 

#leftbanner 

{

	position:absolute;

	top:0;

	left:0;

	padding:10px;

	width:15%;

	border-right: solid 1px black;

	text-align:right;

	font-size:0.7em;

}
 

#main 

{

	position:relative;

	top:0;

	left:20%;

	padding:10px;

	width:75%;

	font-size:0.8em;

}

Open in new window

0
 
LVL 2

Author Comment

by:kmoloney
ID: 20433196
Also, can't I persist the values of certain variables using classes or (shudder) web services?
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20433323
>> Will test both caching and tools.  Mortaza, still the question as to whether or not server needs to be
>> configured specially to handle AJAX extensions...?

Normally nothing especial, all the needed dll files are included automatically when you publish your web site. By the way, if you see some Java Script errors while navigating your pages, you can install the Microsoft AJAX Library.
Ajax Tab control is better than Multiview in several points of view.
You can have partial post backs, not a full post back when you switch to a new tab.
In a screen with dozens of controls, a full post back for a simple tab switching is really annoying for the end user...
0
 
LVL 2

Author Comment

by:kmoloney
ID: 20441289
Mortaza,

Sorry, I'm confused.  Can you save me some time and tell me how to configure and use a partial postback?  Also, if I use a partial postback for a tab A, navigates to tab B, and navigates back to tab A, will the data that the person entered in tab A still be there?
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20444371
Just insert a "Update Panel" inside the tab control and put your controls in that "update panel"
When the controls need to be refresh, just the "update panel" refreshes... (a partial update)

Yes, the data is still present there...
0
 
LVL 2

Author Comment

by:kmoloney
ID: 20456685
Thanks, Mortaza, I will give that a try.
0
 
LVL 2

Author Comment

by:kmoloney
ID: 20479056
Mortaza,

Everything looks good here, except that within each update panel, I have an HTML table with various server controls.  I'm using the calendar extender in the top row, but when the calendar drops down, it displays behind other controls (but not text) in rows below it.

See my question Ref# 23025846.  I am using relative positioning and IE7.  If you can answer that, you'll probably get 500 for that question and 500 for this one as well.

Once I can get this straightened out, I can test out putting some data in there and making sure that it works on a different server.
<!--In this example, CalendarExtender2 is tied to the asp.net textbox control "txtDate".  When the calendar drops down, it displays behind other textboxes and dropdown list boxes.  It displays over text.-->
 

<%@ Page Language="VB" MasterPageFile="~/COS.master" AutoEventWireup="false" CodeFile="StatTab.aspx.vb" Inherits="StatTab" title="Untitled Page" %>
 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

	Namespace="System.Web.UI" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

	&nbsp;

	<asp:ScriptManager ID="ScriptManager1" runat="server">

	</asp:ScriptManager>

	<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" Style="position: relative" Width="90%">

		<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">

			<ContentTemplate>

				<asp:UpdatePanel ID="UpdatePanel2" runat="server">

					<ContentTemplate>

						HEADER INFO:<br /><br />

						

						<table style="width: 100%; position: relative">

							<tr>

								<td colspan="2">

									Current

									Date:</td>

								<td colspan="4">

									<asp:TextBox ID="txtDate" runat="server" Style="position: relative"></asp:TextBox>

                                    <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtDate">

                                    </cc1:CalendarExtender>

                                </td>

							</tr>

							<tr>

								<td style="width: 100px">

									Last Name:</td>

								<td colspan="2">

									<asp:TextBox ID="txtLast" runat="server" Style="position: relative"></asp:TextBox></td>

								<td style="width: 100px">

									First Name:</td>

								<td colspan="2">

									<asp:TextBox ID="txtFirst" runat="server" Style="position: relative"></asp:TextBox></td>

							</tr>

							<tr>

								<td style="width: 100px">

									Job Title:</td>

								<td colspan="2">

									<asp:TextBox ID="txtTitle" runat="server" Style="position: relative"></asp:TextBox></td>

								<td style="width: 100px">

									SSN:</td>

								<td colspan="2">

									<asp:TextBox ID="txtSSN" runat="server" Style="position: relative"></asp:TextBox></td>

							</tr>

							<tr>

								<td style="width: 100px">

									Office Location:</td>

								<td colspan="2">

									<asp:DropDownList ID="ddlLocation" runat="server" Style="position: relative" AutoPostBack="True">

										<asp:ListItem Value="JAK">Jackson</asp:ListItem>

										<asp:ListItem Value="MAD">Madison Heights</asp:ListItem>

										<asp:ListItem Value="RVR">RiverCrest</asp:ListItem>

										<asp:ListItem Value="CHI">Clubhouse Inspiriation</asp:ListItem>

										<asp:ListItem Value="OXF">Oxford Main</asp:ListItem>

										<asp:ListItem Value="FNT">Flint</asp:ListItem>

										<asp:ListItem Value="SAG">Saginaw</asp:ListItem>

										<asp:ListItem Value="BSL">Bayside Lodge</asp:ListItem>

										<asp:ListItem Value="OTH">Other</asp:ListItem>

									</asp:DropDownList></td>

								<td style="width: 100px">

									If Other...</td>

								<td colspan="2">

									<asp:TextBox ID="txtLocationOther" runat="server" Style="position: relative"></asp:TextBox></td>

							</tr>

						</table>

					</ContentTemplate>

				</asp:UpdatePanel>

			</ContentTemplate>

			<HeaderTemplate>

				Header

			</HeaderTemplate>

		</cc1:TabPanel>

'

'

'

'

' [Other Tab Panels

'

'

'

'

		

</asp:Content>

Open in new window

0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20479950
Here is a page using the calendar extender. I've placed a dropdownlist
control and a html select below the associated textbox control. When I
click on the link button to display the calendar it appears to render
over top when I use IE 7 or FireFox 2.
<%@ Page Language="C#" AutoEventWireup="true"

CodeFile="Default.aspx.cs" Inherits="_Default" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/

TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

<ajaxToolkit:CalendarExtender ID="CalendarExtender1"

runat="server" PopupButtonID="LinkButton1"

TargetControlID="TextBox1">

</ajaxToolkit:CalendarExtender>

<asp:TextBox ID="TextBox1" runat="server"></

asp:TextBox>

<asp:LinkButton ID="LinkButton1"

runat="server">LinkButton</asp:LinkButton><br />

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:ListItem>0</asp:ListItem>

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem>3</asp:ListItem>

</asp:DropDownList>

<select id="Select1">

<option selected="selected" value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option></option>

<option></option>

<option></option>

</select>

</ContentTemplate>

</asp:UpdatePanel>

</form>

</body>

</html>

Open in new window

0
 
LVL 2

Author Comment

by:kmoloney
ID: 20496957
No question this would work, since it doesn't involve a table.  My point is, if the CalendarExtender (and the control is is bound too) is placed within an HTML table for positioning purposes, it doesn't seem to work.

Can you show me an example of a calendar extender and its control placed inside an HTML table cell where it does not appear behind server controls in subsequent rows?

You deserve the points for this question, though, since the Calendar Extender is a tangential question.  I could just as easily use validators or code to ensure the content is a date.

The CalendarExtender question is still alive, though, at Ref# 23025846.

Thanks,

Kevin

0
 
LVL 2

Author Closing Comment

by:kmoloney
ID: 31413357
Would have liked to see answer to CalendarExtender control within html table cell, but that's tangential and not what I asked in the question.
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20498567
Dear Moderator,

This question's main zone if Programming for ASP .NET, not classic Active Server Pages.

Please if it is possible, change the main zone.

Kind Regards,
Mortaza Doulaty
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now