I have a gridview that has a template field which contains a link button. When the user clicks on this link button I am calling an OnClick event DisplayModal which runs a method to get the dynamic values to from the database to a datatable to bind to the modal gridview. This method runs ClientScript.RegisterStartupScript to call jquery function openModal() which shows the modal. This works fine.
I have three gridviews on the page. When i scroll down the second gridview and click on the link button the modal opens with the correct values on the modal but it refreshes the page so the scrollbar is back at the top rather than where i clicked on the gridview and then opens the modal.
I want to prevent it from refreshing the page. I have got an update panel around the gridview and PostBackTrigger tag after the modal.
protected void DisplayModal(object sender, EventArgs e)
{
int rowIndex = Convert.ToInt32(((sender as LinkButton).NamingContainer as GridViewRow).RowIndex);
GridViewRow row = gvTeamCAOTDashboard.Rows[rowIndex];
row.Focus();
MeasurecodeClicked = (row.FindControl("lnkBtnEdit") as LinkButton).Text;
GetKPICriteria(MeasurecodeClicked); //calls sql method to bind data
H1.InnerText = "KPI Criteria - " + MeasurecodeClicked;
ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openModal();", true);
}
function openModal() {
$("#myModal").modal('show');
}
<div class="table-responsive">
<asp:updatepanel id="Updatepanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvTeamCAOTDashboard" class="table table-bordered" Width="100%" DataKeyNames="ControlDesc" runat="server" CellPadding="0" AutoGenerateColumns="false" OnRowDataBound="gvTeamCAOTDashboard_RowDataBound" HeaderStyle-HorizontalAlign="Center">
<Columns>
<asp:BoundField DataField="IsWorkingDay" HeaderText="IsWorkingDay" ReadOnly="true" SortExpression="IsWorkingDay" ItemStyle-CssClass="Hide" HeaderStyle-CssClass="Hide" >
<ItemStyle CssClass="Hide" />
</asp:BoundField>
<asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign ="Center" >
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" ForeColor="Black" runat="server" Text='<%# Eval("MeasureCode") %>'
OnClick="DisplayModal" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total" SortExpression="TotalCases" ItemStyle-HorizontalAlign ="Center" ControlStyle-ForeColor="Black">
<ItemTemplate>
<asp:HyperLink ID="TotalCases" runat="server" Text='<%# Eval("TotalCases") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Target" HeaderText="Standard" ReadOnly="true" SortExpression="Target" ItemStyle-HorizontalAlign ="Center" >
<HeaderStyle />
</asp:BoundField>
<asp:BoundField DataField="AvgDaysTaken" HeaderText="Average" ReadOnly="true" SortExpression="AvgDaysTaken" ItemStyle-HorizontalAlign ="Center" >
<HeaderStyle />
</asp:BoundField>
</Columns>
</asp:GridView>
<!-- Modal -->
<div class="modal fade bd-example-modal-lg" id="myModalTeam" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" runat="server" id="H1"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<asp:GridView ID="gvModalTeam" runat="server">
</asp:GridView>
</div>
<div class="modal-footer">
<button type="button" id="closebutton" runat="server" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers >
<asp:PostBackTrigger ControlID="gvTeamCAOTDashboard" />
</Triggers>
</asp:updatepanel>
</div>