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 %>’;

or

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”;
}

Advertisement

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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