0

A control with ID 'contactButton' could not be found for the trigger in UpdatePanel 'contactUpdatePanel'.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /> 
<asp:UpdatePanel ID="contactUpdatePanel" runat="server" UpdateMode="Always">
    <ContentTemplate>
        <asp:ListView ID="contactList" runat="server">
            <ItemTemplate>
                <asp:Panel runat="server">
                    <asp:Label ID="contactLabel" runat="server" Text='<%# Bind("Number") %>' ></asp:Label>
                    <asp:Button OnClick="contactButton_Click" ID="contactButton" runat="server" Text="Assign"/>
                </asp:Panel>
            </ItemTemplate>
        </asp:ListView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="contactButton" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Seems that `contactButton` control is out-of-scope to `Trigger` collection since it contained inside `ListView` - did you try putting `contactButton` just inside `UpdatePanel` directly to see if it work properly? – Tetsuya Yamamoto Mar 19 '18 at 06:34
  • 1
    I think you can just remove the trigger. Anything inside an update panel that causes a postback does not need a trigger. – wazz Mar 19 '18 at 06:41
  • @TetsuyaYamamoto I need the Button to be multiple and generated from the codebehind because it is based on a database model. I am finding a way to make a button dynamically from the code behind and have a onclick event with a specific passed on parameter base on the Model. – Samuel Marvin Aguilos Mar 19 '18 at 06:52
  • @wazz removing it didn't do the job and showed this error Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> – Samuel Marvin Aguilos Mar 19 '18 at 06:53
  • 1
    See my answer here. You must register that button for async postback programatically. https://stackoverflow.com/questions/48439266/how-to-get-the-checkbox-id-that-placed-in-a-repeater-for-update-panel – VDWWD Mar 19 '18 at 07:34

1 Answers1

2

Just remove this line because Listview and button are not outside the update panel so it will work automatically.

<Triggers>
        <asp:AsyncPostBackTrigger ControlID="contactButton" EventName="Click" />       
</Triggers>

Your final code

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /> 
<asp:UpdatePanel ID="contactUpdatePanel" runat="server" UpdateMode="Always">
    <ContentTemplate>
        <asp:ListView ID="contactList" runat="server">
            <ItemTemplate>
                <asp:Panel runat="server">
                    <asp:Label ID="contactLabel" runat="server" Text='<%# Bind("Number") %>' ></asp:Label>
                    <asp:Button OnClick="contactButton_Click" ID="contactButton" runat="server" Text="Assign"/>
                </asp:Panel>
            </ItemTemplate>
        </asp:ListView>
    </ContentTemplate>        
</asp:UpdatePanel>
Jon P
  • 19,442
  • 8
  • 49
  • 72
Anant Jaiswal
  • 136
  • 1
  • 9
  • Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. – Samuel Marvin Aguilos Mar 19 '18 at 06:58
  • Yes, This can be solve by adding `EnableEventValidation="true"` attribute at your `<%@ Page` directory. In some case it shows error due to not any activity in page for while so it maybe solve by refreshing the page. – Anant Jaiswal Mar 20 '18 at 03:39