简体   繁体   English

如何使gridView命令字段按钮进入ajax更新面板PostBackTrigger

[英]How to make a gridView command field button into an ajax update panel PostBackTrigger

I have a gridview in an ajax update panel. 我在ajax更新面板中有一个gridview。 I have set the different button events as AsyncPostBackTriggers but I want the select button to open a child web page so it has to be a postback. 我已将其他按钮事件设置为AsyncPostBackTriggers,但我希望选择按钮打开子网页,因此它必须是回发。 I tried the following: 我尝试了以下方法:

<Triggers>
      <asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowCancelingEdit" />
      <asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowEditing" />
      <asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowUpdated" />
      <asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowUpdating" />
      <asp:AsyncPostBackTrigger ControlID="gvClients" EventName="Sorted" />
      <asp:AsyncPostBackTrigger ControlID="gvClients" EventName="Sorting" />
      <asp:PostBackTrigger ControlID="gvClients" />
</Triggers>

I recieved the following error:" System.ArgumentException: Control with ID 'gvClients' cannot be registered through both RegisterAsyncPostBackControl and RegisterPostBackControl. This can happen if you have conflicting triggers associated with the target control." 我收到以下错误:“ System.ArgumentException:不能同时通过RegisterAsyncPostBackControl和RegisterPostBackControl注册ID为'gvClients'的控件。如果与目标控件关联的触发器冲突,则可能发生。

I tried accessing the select button from code behind and setting it as a trigger. 我尝试从后面的代码访问选择按钮并将其设置为触发器。

This is the code: 这是代码:

   protected void gvClients_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if (e.Row.RowType == DataControlRowType.DataRow)
        {     
            Button btnDtls = (Button)e.Row.Cells[0].Controls[2];
            string btnDtlsId = btnDtls.ID;
            PostBackTrigger trigger = new PostBackTrigger();
            trigger.ControlID = btnDtlsId;
            UpdatePanel1.Triggers.Add(trigger);
        }
    }

In debugging I saw that the ID for the button is "ctl01" but I'm getting this error: "A control with ID 'ctl01' could not be found for the trigger in UpdatePanel 'UpdatePanel1'". 在调试中,我看到按钮的ID为“ ctl01”,但出现此错误:“在UpdatePanel'UpdatePanel1'中找不到ID为'ctl01'的控件”。 Is there a way of accessing a control field select button and setting it as a PostBackTrigger? 有没有一种方法可以访问控制字段选择按钮并将其设置为PostBackTrigger?

Since the button is inside a template, its final id is different and you can get it from the UniqueID property. 由于按钮位于模板内部,因此其最终ID是不同的,您可以从UniqueID属性中获取它。 http://msdn.microsoft.com/en-us/library/system.web.ui.control.uniqueid.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.control.uniqueid.aspx

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

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