How to pass the variable value from asp.net code behind to javascript

.cs side
//Declaring protected type string variable
protected string myMessageFromCodeBehind;

protected void Page_Load(object sender, EventArgs e)
{
//Assigning Value to variable
myMessageFromCodeBehind = "Happy coding, keep coding";
}

I have declared a protected type string variable myMessageFromCodeBehind in asp.net code behind, assign a value to that variable and get it on my .aspx page using javascript given below
var myMessage = "<%=myMessageFromCodeBehind %>";
alert(myMessage);

0 comments:

Post a Comment