简体   繁体   English

在更新面板中时,GridView中的按钮单击不触发

[英]Button click in gridview not firing when inside update panel

<asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" />
<asp:UpdatePanel runat="server" id="pnlUpdate">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="timer1" eventname="Tick"/>
    </Triggers>
    <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="table table-hover table-condensed" 
            GridLines="None" AllowPaging="true" PageSize="20"
            OnPageIndexChanging="GridView1_PageIndexChanging">
        <Columns>
            <asp:BoundField ItemStyle-Width="50%" DataField="Story" HeaderText="Story"/>
            <asp:BoundField ItemStyle-Width="15%" ItemStyle-Wrap="false" DataField="AssignedTo" HeaderText="Assigned To"/>
            <asp:BoundField ItemStyle-Width="15%" ItemStyle-Wrap="false" DataField="Status" HeaderText="Status"/>
            <asp:BoundField ItemStyle-Width="15%" ItemStyle-Wrap="false" DataField="Started" HeaderText="Started"/>
            <asp:BoundField ItemStyle-Width="5%" ItemStyle-Wrap="false" DataField="Updated" HeaderText="Updated"/>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="Buttonid" runat="server" CommandName="ViewItem" Text="View"  BorderStyle="None" BackColor="White" 
                        OnClick="Button_click_event"></asp:Button>   
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <RowStyle CssClass="cursor-pointer" />
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

Button_click_event won't fire when I have update panel, but it works when it is not in the update panel. 当我有更新面板时,不会触发Button_click_event ,但当它不在更新面板中时,它将起作用。

your update panel look like 您的更新面板看起来像

<asp:UpdatePanel ID="upWall" runat="server" ChildrenAsTriggers="true" UpdateMode="conditional">
 <ContentTemplate>
     ....
 </ContentTemplate>
<Triggers>
 <asp:AsyncPostBackTrigger ControlID="Buttonid" EventName="Click"/>
</Triggers>

Try setting UpdateMode="Conditional" and ChildrenAsTriggers="False" to the UpdatePanel.. 尝试将UpdateMode="Conditional"ChildrenAsTriggers="False"到UpdatePanel。

 <Triggers>
            <asp:AsyncPostBackTrigger ControlID="GridView1" />
        </Triggers>

Also remove the EventName attribute for your trigger and try again.. 同时删除触发器的EventName属性,然后重试。

删除按钮的属性,单击CommandName =“ ViewItem”,然后尝试运行,如果不起作用,还添加按钮UseSubmitBehaviour = true的属性。

You could solve this in various ways. 您可以通过多种方式解决此问题。 One way is on rowdatabound in the code behind adding a control that can handle an onclick event, for example a div, and then add a postback handler to your clickable control: 一种方法是在代码中的rowdatabound上添加可处理onclick事件的控件(例如div),然后在其可单击控件中添加回发处理程序:

HtmlGenericControl div = (HtmlGenericControl)e.Row.FindControl("Buttonid");
div.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));

Alternatively, I implemented another workaround that works for me: 另外,我实施了另一个对我有效的解决方法:

place a button outside your gridview, but inside the Updatepanel. 在gridview的外部,但在Updatepanel的内部,放置一个按钮。 Also, add a hiddencontrol, where you are going to store the rowindex clicked. 另外,添加一个hiddencontrol,将在其中存储单击的rowindex。 Then Add to your template field a 'clickable div' (in which you can put a label for your text), that calls a javascript. 然后在您的模板字段中添加一个“可点击的div”(您可以在其中放置文字标签),该标签会调用javascript。 Something like this (you can add a display none style to hide the button).: 这样的事情(您可以添加无显示样式来隐藏按钮)。

  <asp:Button id="Buttonid" runat="server" OnClick="Button_click_event" /> <asp:HiddenField ID="hdnRowClicked" runat="server" Value="" /> <itemtemplate> <div onclick="javascript:rowClicked('<%= Buttonid.ClientID %>','<%= hdnRowClicked.ClientID %>', this);"> <asp:Label ID="lblImgDetail" runat="server" Text="+"></asp:Label> </div> </itemtemplate> 

Then within the javascript function, set the rowindex and call the button to do the postback: 然后在javascript函数中,设置rowindex并调用按钮进行回发:

  function rowClicked(btnId, hdnRowSelected, lnk) { var rowIndex = lnk.parentNode.parentNode.rowIndex - 1; $('#' + hdnRowSelected).val(rowIndex); $('#' + btnId).click(); } 

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

相关问题 当在网格视图内的更新面板内时,Asp 图像按钮单击事件不会为所有行触发 - Asp image button click event not firing for all row when it is inside a update panel which is inside a grid view Asp:更新面板内的按钮单击事件未触发 - Asp:Button click event inside update panel not firing 在ASP.NET更新面板中未触发按钮单击事件 - Button click event is not firing inside Update Panel of ASP.NET 更新面板内的 FileUpload GridView 未在按钮单击时上传文件 - FileUpload GridView inside Update Panel not Uploading Files on Button Click 更新面板中的Gridview PageIndex未在按钮单击时维护 - Gridview inside Update panel PageIndex not maintained on button click 使用更新面板(更新面板外部的按钮)时,不会触发Click事件 - Click event is not firing when using update panel , the button outside the update panel 在更新面板中放置链接按钮不会触发链接按钮的click事件 - placing link button inside update panel not firing the click event of link button 更新面板上的按钮单击事件未在多个用户控件中触发 - button click event on update panel not firing in multiple user control 在更新面板的gridview中触发按钮 - trigger for a button in a gridview in update panel 当Gridview位于更新面板中时,模式弹出窗口无法正常工作 - Modal Pop Up not working properly when Gridview is inside Update Panel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM