ASP.Net Set or GET JavaScript Variable Value from Code Behind

Assign Javascript Variable value which is used in Code behind

To set Javascript Variable from Code

Declate Public variable in Code which we can access from ASPX Page

ASPX Page :

For Simple Javascript VAriable

var JavaVar1 = ‘<%=strJavaVariable %>’;


With Control Value

<input id=”hiddenVariable” name=”hiddenVariable” value='<%=strJavaVariable %>’ />

Code Behind :

public string strJavaVariable = string.Empty;

protected void Button1_Click(object sender, EventArgs e)
strJavaVariable = “Button Click Event Called”;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s