You can use ASP.NET variables which are global (public of course) as follows:
Suppose in C# file you have:
public string random= "0";
You can use the variable in JS (actually the ASP.NET page replaces the variable name on runtime) as follows:
var var1 = '<%= random %>';
2. Simulating ASP.NET AJAX Applications
While simulating ASP.NET AJAX applications, we cannot really differentiate between the request being Async and if the page has posted back. Here’s a simple way to find it out – Just add a delay in the function which is run as an AJAX request. For Eg.
This will provide a delay of 10 seconds. So when the function freezes at this point for 10 secs, you can check whether other parts of the site are responsive. If they ain’t you know that its not an AJAX request.
var var2 = document.getElementById('<%= Label1.ClientID %>').getAttribute("InnerHtml");
In the above piece of code, Label1 is a Label and we use the InnerHtml attribute for extracting the Text Label.
4. Triming Strings in JS
strvar = strvar.replace(/^\s+|\s+$/g, '');
I’ll continue with few more tricks I have learnt in the next post. Thanks for the patience of reading the post :)
Announcing the Microsoft Store – the first online store where you can purchase the full selection of Microsoft products directly from the source.
Go to www.MicrosoftStore.com and find the largest selection of Microsoft software, devices and hardware. There are lots of reasons to visit the store:
· Immediate software download option with the largest download catalog of Microsoft titles
· Simple and secure purchase – all at your fingertips
· Most up-to-date selection of and information on your favorite Microsoft products including Xbox, Zune, Office, Windows and much more
Ps. Shipping Restrictions
The United States Microsoft Store cannot ship to international addresses. Microsoft Store cannot yet ship to P.O. Boxes, U.S. Territories, or APO addresses at this time. We plan to add support for APO addresses in early 2009.