I have read quite a few threads but I cannot figure out why this will not work. I am creating a SharePoint Web Part that will serve as a navigation bar. Everything works great until I try and reference a C# Variable in the JS Code.
Here is my C# from the VisualWebPart1UserControl.ascx.cs:
public class myClass
{
public string theValue = "hi";
}
Here is the HTML/JS from the VisualWebPart1UserControl.ascx Page:
<script type="text/javascript">
function getMyValue() {
var myVar = "<%= myClass.theValue %>";
alert(myVar);
}
<li><a href="http://maindt"
onmouseover="getMyValue(), mopen('m1')"
onmouseout="mclosetime()">MAINDT Home</a>
<div id="m1"
onmouseover="mcancelclosetime()"
onmouseout="mclosetime()">
<a href="">Site 1</a>
<a href="">Site 2</a>
<a href="">Site 3</a>
</div>
</li>
What happens is when I hover my mouse over the "MaindDT Home" drop down, I get the alert(myVar) which is good but the content is <%=myClass.theValue%> when I'm expecting it to display the value of theValue which is "Hi"