简体   繁体   English

直到第二次单击,UpdatePanel中的ASP.NET GridView才会更新

[英]ASP.NET GridView inside UpdatePanel doesn't update until second click

I've looked for answers online but I have not found any answer. 我已经在网上寻找答案,但没有找到答案。 I have a GridView inside an UpdatePanel and one Linkbutton column to show some detail in a Bootstrap modal. 我在UpdatePanel和一个Linkbutton列中都有一个GridView,以显示Bootstrap模态中的一些详细信息。 I had a problem that when the user clicks on the LinkButton the event OnClick doesn't fire, so, to solve that I made a fuction in Javascript that only causes a click in another LinkButton to fire the OnClick event. 我遇到一个问题,当用户单击LinkBut​​ton时,事件不会触发OnClick,因此,为了解决这一问题,我使用Javascript进行了功能设置,仅导致另一个LinkBut​​ton中的单击触发了OnClick事件。

Now it works fine, but nothing changes until the second click. 现在,它可以正常工作,但是在第二次单击之前没有任何变化。

ASP.NET code ASP.NET代码

<asp:UpdatePanel ID="upContent" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <table align="center">
            <tr>
                <td>
                    <asp:GridView ID="grvOrderTracing" runat="server" EmptyDataText="There are no pending orders for the selected date" AutoGenerateColumns="False" DataSourceID="SqlDTSgetOrdersByDate" CssClass="table table-striped table-hover table-responsive" GridLines="None" AllowPaging="True" PageSize="8" >
                        <PagerStyle CssClass="pagination-ys" />
                        <Columns>
                            <asp:BoundField DataField="Order ID" HeaderText="Order ID" SortExpression="Order ID" >
                                <ControlStyle CssClass="hide" />
                                <FooterStyle CssClass="hide" />
                                <HeaderStyle CssClass="hide" />
                                <ItemStyle CssClass="hide" />
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="Order Number">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lbtShowMoreInfo" runat="server" data-toggle="modal" data-target="#showLog" CommandName="OrderID" Text='<%# Bind("[Order Number]") %>' style="cursor: pointer; font-weight: bold;" OnClientClick="ActivityLog(this);">
                                    </asp:LinkButton>
                                    <asp:LinkButton ID="lbtActivityLog" runat="server" CommandName="OrderID" CssClass="hide" OnClick="ActivityLog_Click" Text='<%# Bind("[Order ID]") %>' ></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDTSgetOrdersByDate" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="sp_getOrdersByDate" SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="False">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="0" Name="filter" Type="Int32" />
                            <asp:Parameter Name="startDate" Type="String" />
                            <asp:Parameter Name="endDate" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="upLog" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <!-- Modal -->
        <div id="showLog" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog modal-lg" >
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                         <h4 class="modal-title" id="myModalLabel">Orden Log</h4>
                    </div>
                    <div class="modal-body">
                        <asp:GridView ID="grvLog" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDTSgetTracing" CssClass="table table-striped table-hover table-responsive" GridLines="None" >
                            <Columns>
                                <asp:BoundField DataField="Movement Date" HeaderText="Movement Date" SortExpression="Movement Date" ReadOnly="true" DataFormatString="{0:dd/MM/yyyy HH:mm}" />
                                <asp:BoundField DataField="User" HeaderText="User" SortExpression="User" ReadOnly="true" />
                                <asp:BoundField DataField="Action" HeaderText="Action" SortExpression="Action" ReadOnly="true" />
                                <asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments"/>
                             </Columns>
                         </asp:GridView>
                         <asp:SqlDataSource ID="SqlDTSgetTracing" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="sp_getTracing" SelectCommandType="StoredProcedure">
                             <SelectParameters>
                                 <asp:Parameter  DefaultValue="0" Name="ord_id" Type="Int32"/>
                             </SelectParameters>
                         </asp:SqlDataSource>
                     </div>
                 </div>
             </div>
         </div>
     </ContentTemplate>
</asp:UpdatePanel>

Javascript code JavaScript代码

function ActivityLog(lbt) {
    lbt.nextSibling.nextSibling.click(); //Find the other LinkButton and click
}

C# Code C#代码

protected void ActivityLog_Click(object sender, EventArgs e)
{
    SqlDTSgetTracing.SelectParameters["ord_id"].DefaultValue = ((LinkButton)sender).Text;
    SqlDTSgetTracing.Select(DataSourceSelectArguments.Empty);
    grvLog.DataBind();
    upLog.Update();
}

When clicking the first time 第一次单击时

When clicnking the seccond time 敲第二秒时

After clicking twice now the data is displayed in the GridView. 单击两次后,数据将显示在GridView中。

I want that from the first click the data being displayed in the GridView. 我希望首先单击GridView中显示的数据。

I think you might want to append return false; 我认为您可能想附加return false; to the end of OnClientClick to prevent the rest of that control's click event (coded by ASP.NET for you) from running. OnClientClick的末尾,以防止运行该控件的其余click事件(由ASP.NET为您编码)。 That will ensure only the LinkButton you care about will postback. 这样可以确保只有您关心的LinkButton会回发。

OnClientClick="ActivityLog(this);return false;"

Not sure if that will fix the need for clicking twice or not, but maybe! 不确定是否可以解决单击两次的需要,但是也许可以!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript function 没有被调用 - ASP.NET 和 UpdatePanel - Javascript function doesn't get called - ASP.NET and UpdatePanel asp.net usercontrol不会在updatepanel中激活javascript - asp.net usercontrol won't fire javascript inside updatepanel Asp.Net FileUpload在Ajax UpdatePanel上不起作用 - Asp.Net FileUpload doesn't work on Ajax UpdatePanel 单击一个ASP.NET按钮(位于UpdatePanel内部)以清除文本框(位于UpdatePanel外部) - Click an ASP.NET Button (locate inside an UpdatePanel) to clear a TextBox (locate outside of the UpdatePanel) 在UpdatePanel内部的Gridview中进行文本框控件验证c#ASP.Net - Text Box Control Validation In Gridview inside UpdatePanel c# ASP.Net ASP.Net - AJAX UpdatePanel中的Javascript - ASP.Net - Javascript inside AJAX UpdatePanel ASP.NET UpdatePanel:在UpdatePanel更新上注入Javascript - ASP.NET UpdatePanel: Injecting Javascript on UpdatePanel update ASP.Net GridView复选框,单击“更新另一个”复选框 - ASP.Net GridView checkbox click update another checkbox 使用FireFox时,updatepanel中的asp.net按钮无法触发Jquery函数 - asp.net button inside updatepanel not firing Jquery function on click when using FireFox jQuery触发器asp.net单选按钮在更新面板内部单击 - jQuery trigger asp.net radiobutton click inside of update panel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM