ControlID could not be found for AsyncPostBackTrigger

。_饼干妹妹 提交于 2019-12-12 21:38:06

问题


  <asp:UpdatePanel ID="CartUpdatePanel" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID='<%= rdoSelect.ClientID %>'/>
        </Triggers>
        <ContentTemplate>
            <asp:Timer ID="cartTimer" Interval="5000" runat="server" OnTick="cartTimer_Tick">
            </asp:Timer>
            <asp:GridView ID="gridCartSearch" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:TemplateField HeaderText="Select">
                        <ItemTemplate>

                            <asp:HiddenField ID="Serial" runat="server" Value='<%# Eval("serialnum") %>' />
                            <asp:RadioButton ID="rdoSelect" runat="server" AutoPostBack="true" GroupName="radioBtns"
                                OnCheckedChanged="rdoSelect_CheckedChanged" />
                        </ItemTemplate>
                    </asp:TemplateField>

                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

I'm getting the following error

A control with ID '<%= rdoSelect.ClientID %>' could not be found for the trigger in UpdatePanel 'CartUpdatePanel'.


回答1:


Change the following line:

<asp:AsyncPostBackTrigger ControlID='<%= rdoSelect.ClientID %>'/>

to:

<asp:AsyncPostBackTrigger ControlID='rdoSelect'/>

You cannot use server side tags inside of a server control (like AsyncPostBackTrigger). Instead you should use the ID of the control and the asp.net runtime will dynamical replace it with the proper client side id.




回答2:


I tried <asp:AsyncPostBackTrigger ControlID='rdoSelect'/> but it’s not working.

I found a solution here A control with ID 'ImageButton5' could not be found for.

The AsyncPostBack should be registered whenever a row is created.

protected void gridCartSearch_RowCreated(object sender, GridViewRowEventArgs e)
        {
            Control radioControl = e.Row.Cells[0].FindControl("rdoSelect");
            if (radioControl != null)
            {
                cartScriptMgr.RegisterAsyncPostBackControl(radioControl);
            }

        }

Update the Update Panel On rdoSelect_CheckedChanged

  protected void rdoSelect_CheckedChanged(object sender, EventArgs e)
        {
            ....
            CartUpdatePanel.Update();

        }

using <asp:AsyncPostBackTrigger ControlID='rdoSelect'/>

Thanks All




回答3:


You should not have the client id. Just put rdoSelect as the ID. You should also put a tag EventName to be CheckedChanged




回答4:


The ControlID is the asp.net control id defined in the aspx markup and not the client id, change it as follows:

<asp:AsyncPostBackTrigger ControlID="rdoSelect"/>

Should work



来源:https://stackoverflow.com/questions/5894474/controlid-could-not-be-found-for-asyncpostbacktrigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!