A lot of users ask me how to pass value from code behind to javascript. Although it is very simple.
Here’s an example
Following is the Default.aspx page script
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to pass Javascript value to Server Side</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var AuthorName = "<%=AuthorName %>";
alert(AuthorName.toString());
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Following is the Default.aspx.cs page script.
protected string AuthorName = "Aamir Hasan";
protected void Page_Load(object sender, EventArgs e)
{
}
Output

Download
Pass Code Behind value to javascript.zip (1.00 kb)
Live demo
Note: If you have better solution, please comment here to share with us.