I'm trying to access a variable in Javascript from the server side (c#). I've declared this variable as public from the server side:
public string elementSliderAppend;
and accessing in javascript using:
<%=elementSliderAppend %>
So far so good, however the variable doesn't seem to be updated after the update panel refresh in my aspx page.
The variable changes all okay in the backend but the change is not happening in Javascript. I have placed the accessing of the variable inside the update panel so it should refresh but it doesn't.
below is the code from the aspx page
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="10000">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:Asyncpostbacktrigger controlid="Timer1"> </asp:Asyncpostbacktrigger>
</Triggers>
<ContentTemplate>
<div id="flexViewer" class="flexslider">
</div>
<script type="text/javascript">
function getImgHtml() {
return <%=elementSliderAppend %>;
}
</script>
</ContentTemplate>
</asp:UpdatePanel>
Calling the variable from the below code (also on the aspx page)
function pageLoad(sender, args) {
$("#flexViewer").html("<ul class=slides>" + getImgHtml() + "</ul>");
flexSliderRUN();
}
NEW CODE
I've now inserted the below code inside the updatepanel above
<asp:HiddenField ID="hiddimgHtml" runat="server" />
Im setting the hidden field value from code behind using
hiddimgHtml.value= elementSliderAppend;
using the below in my javascript file to access the value
var value = $("#hiddimgHtml").val();
alert(value);
$("#flexViewer").html("<ul class=slides>" + value + "</ul>");
However on the refresh im getting a very nasty looking error
POST http://:1562/FridayViewer.aspx 500 (Internal Server Error) ScriptResource.axd?d=xz1-gVxgQeQi9AUxmqDjtx8455SyoL-b2LZdBEiJTo8-XZn2n4ZRBb…NYDXi9xlT_-BAcGHV0ZqGBzbItBzEvsjInrEIWh3G93x0XMte0bSN00lh0&t=6119e399:6073 XHR finished loading: "http://:1562/FridayViewer.aspx". ScriptResource.axd?d=xz1-gVxgQeQi9AUxmqDjtx8455SyoL-b2LZdBEiJTo8-XZn2n4ZRBb…NYDXi9xlT_-BAcGHV0ZqGBzbItBzEvsjInrEIWh3G93x0XMte0bSN00lh0&t=6119e399:6073 Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500 ScriptResource.axd?d=xz1-gVxgQeQi9AUxmqDjtx8455SyoL-b2LZdBEiJTo8-XZn2n4ZRBb…RNYDXi9xlT_-BAcGHV0ZqGBzbItBzEvsjInrEIWh3G93x0XMte0bSN00lh0&t=6119e399:237