Friday, 21 December 2018

get the value of label in asp:repeater in jquery modal popup

I am trying to get the value of of a label in asp:reader in a jquery popup. I have tested this tutorial ASP.NET Repeater with jQuery Dialog Popup and it works fine. However when I try to use the same concept in my script no data is shown. I have viewed the code behind and there are values. Here is my script.

    <script type="text/javascript">
    $(document).ready(function() {
        $("#btnclickedit").click(function () {
            var currentRow = $(this).parents("tr");
            var MBBody = currentRow.find("span[id*='messageBody']").text();
            $("#ContentPlaceHolder1_bmessageedit").text(MBBody);
            $("#divpopupedit").dialog({
                width: 600,
                height: 580,
                title: "Edit a Message",
                modal: true,
            });
        });
    })
</script>
    <div id="divpopupedit" style="display:none">
            <div class="form-group">
                <label for="BodyMessage">Reply:</label><br />
                <asp:Label ID="bmessageedit" runat="server" />
                <asp:HiddenField ID="MessageBoardIDEdit" runat="server" />
            </div>       
    </div>
                       <asp:Repeater ID="myRepeater" OnItemDataBound="myRepeater_ItemDataBound" runat="server">
            <HeaderTemplate>
                <div class="messageBox">
                    <table id="messageDetails">
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label ID="title" Font-Bold="true" Text='<%# Eval("MessageTitle") %>' runat="server" />
                        <span class="subtitle">Posted By: <%# Eval("EmployeeName") %> | <%# Eval("DateTimePosted") %> </span> <span id="messageED" class="messageActions" runat="server"> <button type="button" class="ui-button ui-widget ui-corner-all" id="btnclickedit">Edit</button> | <button type="button" class="ui-button ui-widget ui-corner-all" id="btnclickdelete">Delete</button> </span>  
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:label ID="messageBody" Text='<%# Eval("Message") %>' runat="server" />                     
                        <asp:HiddenField ID="MBCategoryID" Value='<%# Eval("MBCategoryID") %>' runat="server" />
                        <asp:HiddenField ID="PostedBy" Value='<%# Eval("PostedBy") %>' runat="server" />
                        <asp:HiddenField ID="MessageBoardID" Value='<%# Eval("MessageBoardID") %>' runat="server" />
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                 </table>
                </div>
            </FooterTemplate>
        </asp:Repeater>

UPDATE When I hard code a value the data is displayed. So the issue is the JQuery script does not read the messageBody label value in the repeater.

var currentRow = $(this).parents("tr");
var MBBody = "15";
$("#ContentPlaceHolder1_bmessageedit").text(MBBody); 



from get the value of label in asp:repeater in jquery modal popup

No comments:

Post a Comment