Click here to Skip to main content
15,742,973 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
Hello All,

I want to access string variable value in javascript on same page,
so ,how can i do this.

for e.g

I have a one property like
public string Hidnum
get {}

and in Page_Load event I am just declaring string varisble like
string Hnum = Hidnum;

So i want to access Hnum variable in Javascript function of that page.
Updated 7-May-12 23:55pm

you can achieve this by adding hiddenfield in design page and in set of property also set the value to hiddenfld and you can get the value of hdnfld in javascript by using document.getElementId('hdnprop').value.

Hope it helps you!!
Share this answer
On code behind
public partial class _Default : System.Web.UI.Page 

    public string str = "its a test...";


On .aspx Page
<script type="text/javascript">
    var str="<%=str%>";
Share this answer
var QueryString = function () {
  // This function is anonymous, is executed immediately and
  // the return value is assigned to QueryString!
  var query_string = {};
  var query =;
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
        // If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = pair[1];
        // If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]], pair[1] ];
      query_string[pair[0]] = arr;
        // If third or later entry with this name
    } else {
    return query_string;
} ();
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900