I have an asp.net label , label2 which is in an ajax update panel.
<div id="Div1" class="InsertBar">
<asp:Label ID="Label2"
runat="server" Visible="true" Font-Bold="true">
</asp:Label>
<asp:GridView>
<!-- my gridview template and columns -->
</asp:GridView>
</asp:Panel>
</div>
This update panel is displayed in a jquery dialog. The jquery dialog is opened on button click event.
I am assigning a value for the label label2 in asp.net code behind on each button click.
I am trying to access label2 in the javascript code using the following code.
var newtitle = $('#<%=Label2.ClientID%>').text();
The javascript function is below . The function is called from asp.net code behind
<script type="text/javascript">
function ViewModelPopup1() {
var newtitle = $('#<%=label2.ClientID%>').text();
$(Div1).dialog('option', 'title', newtitle);
}
</script>
The problem I have is , for the first time the asp.net button is clicked the javascript variable new title gets assigned to the asp.net label2
. But on subsequent button clicks the javascript variable newtitle does not get updated . Any suggestions on how I can update the javascript variable to the asp.net label on each button click ?
Just my thoughts. I have the asp.net label within an ajax update panel. Should I also use any ajax for the javascript ???
$(Div1).dialog('option', 'title', newtitle);
. You need to accessDiv1
like'#Div1
', otherwise you will get a null value. Otherwise I'm not sure what the problem would be. I would stick to keeping everything either client or server side though, that might be causing a problem, but again, I'm not sure. – B-M Jul 26 '13 at 13:42