Accessing Server-Side Variables, Property In JavaScript: C#
At times there may be a requirement to access the
server-side variables JavaScript. To achieve the same we can follow the
following:
The language used for server-side variable is c#.
For a server-side variable to be accessed in JavaScript, the
variable declared must be public.
Server-Side C# Code:
public string strTempVar = "some value";
JavaScript Code:
<script type="text/javascript" language="javascript">
var strTempVarValue = "<%= strTempVar%>";
alert(strTempVar);
</script>
The script written would give you the value in javascript.
The same can be used for accessing property as well.
Regards
Vivek Joshi
No comments:
Post a Comment