简体   繁体   中英

Why my asp.net MODAL doesn't display data?

I am trying to display a gridview inside ajax MODAL but it doesn't show the gridview. It shows every other element that I put INSIDE it but not a gridivew. I tried to display gridview outside the modal and it works but not inside modal. Why ?

Code:

<asp:Panel ID="pnlLastHearingDates" CssClass="modalPopup" runat="server" HorizontalAlign="Center" Visible="true">
 <asp:GridView runat="server" ID="grdViewLastHearingDates" AllowPaging="true" PageSize="5" OnPageIndexChanging="grdViewLastHearingDates_PageIndexChanging"
               OnRowCommand="grdViewLastHearingDates_RowCommand" PagerStyle-BackColor="#99CC99" HeaderStyle-BackColor="#99CC99" DataKeyNames="pk_Cases_CaseID" PagerStyle-Font-Size="12.5px" PagerStyle-ForeColor="Black" PagerStyle-HorizontalAlign="Center" AutoGenerateColumns="false" OnRowEditing="grdViewLastHearingDates_RowEditing"
               CssClass="table table-condensed table-bordered table-striped table-responsive">
   <Columns>
        <asp:BoundField DataField="pk_Cases_CaseID" HeaderText="Case ID" />
        <asp:BoundField DataField="CaseNo" HeaderText="Case No" />
        <asp:BoundField DataField="NextHearingDate" HeaderText="Next Hearing Date" />
        <asp:BoundField DataField="DaysRemaining" HeaderText="Days Remaining" />
   </Columns>
 </asp:GridView>
</asp:Panel>

<asp:Button ID="btnShowLasthearingDates" runat="server" OnClick="btnShowLasthearingDates_Click" CssClass="btn btn-primary" />
<asp:ModalPopupExtender ID="mdlLastHearingDates" runat="server" TargetControlID="btnShowLasthearingDates" PopupControlID="pnlLastHearingDates">

.cs code:

protected void btnShowLasthearingDates_Click(object sender, EventArgs e)
    {
        ShowLastHearingDates();
        pnlLastHearingDates.Visible = true;
    }

The issue here is probably with the TargetControlId attribute of the ModalPopupExtender .

Try removing the Button ID from there and instead take a Hidden Field control in your aspx page and give it an ID. Now put that ID into the TargetControlId attribute and try clicking your button.

Your code would look like this :

<asp:HiddenField ID="HdnFld1" runat="server" />
                                        <asp:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="MPE" runat="server"
                                            CancelControlID="btnCancel"
                                            TargetControlID="HdnFld1" PopupControlID="Panel1"
                                            PopupDragHandleControlID="PopupHeader" Drag="true"
                                            BackgroundCssClass="ModalPopupBG">
                                        </asp:ModalPopupExtender>

Also, you can keep CausesValidation="false" for your button just in case it stops postback due to validation, but again, you might handle it since that would postback without any kind of data checks on the client side.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM