Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 ???

share|improve this question
    
Can we see the entire javascript/jquery function that you having issues with? It may help a little more. –  B-M Jul 25 '13 at 21:33
    
I updated the code .. But am not sure if it would be helpful. Let me know if anything is not clear. I will try my best –  PowerCoder Jul 25 '13 at 21:34
    
Can we also see your button click code? –  Kaushal De Silva Jul 25 '13 at 22:26
    
If this your true code $(Div1).dialog('option', 'title', newtitle);. You need to access Div1 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
    
Hey Brett ! Thank you ! The problem actually is that the var newtitle doesnt get the updated value of the of the asp.net label . The label is within an ajax update panel . I was wondering if the javascript code should also use some kind of ajax ?? –  PowerCoder Jul 26 '13 at 14:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.