I am developing an application for students.
I want to display the total marks of the logged in student on the Header of the Master Page.
When the student clicks on the total marks, the page will go to a details page where student can see all the marks he has received.
The marks are coming from different Web Services. In order to display the Total Marks in Header which is in the Master Page I have to call all the web services.
When I go to the details page again I have to call the same Web Services. This will make the system slower.
Is there a way to call the Marks Web Services ONCE and store the marks somewhere and use the stored results to display marks on the details page?
Thanks,
Prashant SrivastavaPosted Oct 5, 2013, 10:48 PM
You can refer to below code snippet but it not the exactly for the same purpose.
function fnGetAmperDetails()
{
// use jquey ajax to retrieve data from web service
// return that data
}
function fnSetAmperDetailsInSession()
{
var objamper = json.parse(fnGetAmperDetails());
var objdetails = {};
objdetails.ID = objamper.ID ;
objdetails.AmperName =objamper.AmperName;
sessionStorage.setItem("AmperDetails", json.serialize(objdetails));
}
// Page 1 : From here you will set the marks details
$(document).ready(function(){
fnSetAmperDetailsInSession();
});
// Page 2 : where you want to retrieve the amper details
$(document).ready(function(){
var mydetails = json.parse(sessionStorage.getItem("AmperDetails"));
// Here in you scenario "AmperName" will hold the marks.
var AmperName = mydetails.AmperName;
});
r pPosted Oct 5, 2013, 3:50 PM
Do you have any example of the techniqe using JASON.
I have not done this before. I assume that you are talking about an Object of a C# class.
Thanks
Prashant SrivastavaPosted Oct 5, 2013, 8:15 AM
You can do this by storing the details of the marks of different subjects in an object (use JSON2 to serialize this) and then use SessionStorage.setItem to set that JSON serialized object to store the data (marks coming from Web service) and use it where ever required.
NOTE :
1. This is client side so it is better from performance aspect.
2. SessionStorage is a client side technique and will resist till browser for particular session is open. Once browser is closed then that will be lost (This is applicable for your case) .
Implement the same and you will be done with your task in much effecient manner.
Regards,
Prashant Srivastava
Posted Oct 4, 2013, 6:08 AM
Don't go for static variables, it is not thread safe.
What do you mean by global variables?
Do you meant to say application variables? Application variables are not session specific, it will have same value across all the sessions.
r pPosted Oct 4, 2013, 5:41 AM
Is there a better approach than Session Variables; may be I can use Global Variable or Static Class - not sure about it!
Posted Oct 4, 2013, 1:17 AM
But you should think the following also, after the student login, if anyone update the mark it will not get reflect immediately. The student should log-off then login then you will get the updated result.