0

I have a gridview that get binds dynamically. i have a linkbutton attached with every row that opens a modal popup window which I need to show some text which is in a hidden field in gridview.

I need to call a javascript function that sets the value of the label in the popup panel with the text of the hidden field. The problem is that the value is always blank when the popup is displayed.

Java script code is -

  function SetNotesonModal(note)
   {
        //debugger;
        var notes = document.getElementById(note.id).innerHTML;
        document.getElementById('ctl00_ContentPlaceHolder1_popupLblNote').value = notes;
   }

Code for calling the function is -

lnkViewNotes.Attributes.Add("OnClick", "return SetNotesonModal(" + e.Row.FindControl("lblNote").ClientID + ");");

The controls in gridview are as -

<ItemTemplate>
     <asp:Label ID="lblNote" runat="server" Text='<%# Bind("notes") %>'></asp:Label>
     <asp:LinkButton ID="lnkViewNotes" runat="server">View</asp:LinkButton>
     <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="lnkViewNotes" PopupControlID="Panel2" CancelControlID="popupBtnClose">
     </asp:ModalPopupExtender>
</ItemTemplate>

And the panel for popup is -

<asp:Panel ID="Panel2" runat="server" ScrollBars="Auto" align="center" Style="display: none"
    CssClass="modalPopup">
    <table class="border" style="text-align: left; height: 100%" width="100%">
        <tr align="left" style="background-color: #5D7B9D; color: White">
            <th>
                Notes
            </th>
        </tr>
        <tr>
            <td>
                <asp:Label ID="popupLblNote" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="popupBtnClose" runat="server" Text="Close" />
            </td>
        </tr>
    </table>
</asp:Panel>

The javascript function is being called perfectly and its is also setting value of the label in popup panel correctly but not sure why the popup comes blank every time.

Any kind of help is welcome.

Thanks

akhil
  • 1,202
  • 3
  • 21
  • 43
  • Using .net you can use ClientID to get the client id that is rendered in the client as HTML. You have already used it and everything looks fine. I'd suggest you to Check where your Javascript is not working. May be you can post the HTML that has been generated. Or you can check it using Firebug to see what is being generated. – Rajesh Aug 08 '12 at 10:15
  • My javascript is working fine I debugged it its setting the values as well but dont know why its not holding that value. Does it have something to do with link button as it might be posting back and causing the values to be lost – akhil Aug 08 '12 at 10:18

1 Answers1

0

For every linkbutton or button that should not trigger post back You should try adding:

OnClientClick="return false;"

Also take a look at postback with jquery

Community
  • 1
  • 1
rumburak
  • 1,097
  • 11
  • 19