.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Use Server side variable on client side

Posted By:shankey       Posted Date: July 21, 2011    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This article will explain how to use server side variable on client side and get the value of server side to the client side

In this article you will learn how to use server side variable on client side.

I came across a situation where i need to keep a common variable declared in a class file. This variable will hold list of comma separated file type.

This situation arose to keep maintanence as low as possible so that if we need to add/remove a file type there should be less overhead in change.

To use server side variable in client side or in javascript then you can write as shown below.

 function ValidateFileUpload() {
 alert("Only " + '<%= ViewStateAllowedFileType %>' + " files are allowed to upload");
In above code
is a server side variable declared as shown below.

 public string ViewStateAllowedFileType
            if (ViewState["AllowedFileType"] != null && ViewState["AllowedFileType"] != string.Empty)
                return ViewState["AllowedFileType"].ToString();
            return string.Empty;
            ViewState["AllowedFileType"] = value;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend