Hi,

in some scenarios it would be nice to have a initial value already
written to the page instead of waiting for the first Ajax.NET call. In
one of the web sites of my companies product we want to display data
of running machines in the corrugated industry. The table will display
each machine with their machine code and speed, counted and expected
sheets, as other information like order and customer info. This data
is cached on the web server for 1 second (counted sheets are changing
every second, as you can imagine). With the first version of the page
there was a onLoading message when the user opened the page. After a
short time (the time to run the AjaxMethod and to transport the data
back over slow connections) the current situation could be displayed.

Whouldn't it be nice to have the initial values already in the page?

Nothing easier than this. Ajax.NET Professional allows you to
serialize any .NET object into JSON format which can be written to the
initial page output. See following code:


protected void Page_Load(object sender, System.EventArgs e)
{
  DataSet ds = new DataSet();

  // ... fill it from a SQL server with SqlDataAdapter, incomplete code
  da.Fille(ds);

  StringBuilder sb = new StringBuilder();
  sb.Append("<script type=\"text/javascript\">\r\n");
  sb.Append("var initialDS = ");

  // now serialze the DataSet to a JSON string
  string s = AjaxPro.JavaScriptSerializer.Serialize(ds)
  sb.Append(s);

  sb.Append(";\r\n</script>");

  // write the JSON data to the client side JavaScript
  this.RegisterClientScriptBlock("initialValues", sb.ToString());
}


The client-side JavaScript code can now access the initialDS variable.
This is very cool, I think. But have in mind: if it is very slow to
get the data your initial page request will be slow, too. In this
scenarios it would be nicer to the user to have the initial empty page
there and a status onLoading indicator instead. But if your data can
be read from a cache object it is great to use it that way.

-- 
Best regards | Schöne Grüße
Michael

Microsoft MVP - Most Valuable Professional
Microsoft MCAD - Certified Application Developer

http://weblogs.asp.net/mschwarz/
http://www.schwarz-interactive.de/
mailto:[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Ajax.NET Professional" group.

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]

For more options, visit this group at http://groups.google.com/group/ajaxpro

The latest downloads of Ajax.NET Professional can be found at 
http://www.ajaxpro.info
-~----------~----~----~----~------~----~------~--~---

Reply via email to