Googled this and tried all responses I've found but cannot find the right answer.
Trying to simply pass code from code-behind (C#) to aspx (more specifically a javascript variable)
Code behind:
public partial class _Default : System.Web.UI.Page
{
public string greetings = "hello";
protected void Page_Load(object sender, EventArgs e)
{
}
}
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>My page</title>
<script>
var greeting2;
function GetGreeting()
{
greeting2 = <%=greetings%>;
}
</script>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
I've tried using a get method in the code behind rather than just a public variable but this has the same effect. I've also tried <%=this.greetings%> (with and without = sign). Nothing works. help!