locked
A control with ID 'chkEmp' could not be found for the trigger in UpdatePanel 'UpdatePanel2' RRS feed

  • Question

  • User940894612 posted

    Hi

    I keep getting the above error when loading up the page.  Please see my source code:

    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <div class="row">
                        <div class="col-lg-2">Filter bookings by type:</div>
                        <div class="col-lg-4">
                            <asp:DropDownList ID="ddlBookingType" runat="server" onselectedindexchanged="ddlBookingType_SelectedIndexChanged" AutoPostBack="True" class="form-control"> 
                                <asp:ListItem Value="6" Selected="True">Choose...</asp:ListItem> 
                                <asp:ListItem Value="0">All Bookings</asp:ListItem>
                                <asp:ListItem Value="1">New Bookings</asp:ListItem>
                                <asp:ListItem Value="2">Approved Bookings</asp:ListItem>
                                <asp:ListItem Value="3">Completed Bookings</asp:ListItem>
                                <asp:ListItem Value="4">Deleted Bookings</asp:ListItem>
                                <asp:ListItem Value="5">Future Bookings</asp:ListItem>
                            </asp:DropDownList>
                        </div>
                        <div class="col-lg-6"></div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2">
                        </div>
                        <div class="col-lg-10">
                            <p>
                            <asp:GridView ID="grdvBookings" ClientIDMode="Static" runat="server" CssClass="gridview" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="True" DataKeyNames="BookingID,BookingRef" CellPadding="10" GridLines="None" >
                                <PagerSettings PageButtonCount="10" />
                                <PagerStyle cssClass="Test"/>
                                <RowStyle BorderStyle="None" BackColor="#FFFFFF" HorizontalAlign="Center" ForeColor="#333333"></RowStyle>
                                <Columns>
                                    <asp:HyperLinkField Text="Click for more info"  DataNavigateUrlFormatString="~/Admin/Bookings/BookingDetails.aspx?BookingId={0}" HeaderText="Go To Booking" DataNavigateUrlFields="BookingRef" />
                                    <asp:BoundField HeaderText="Booking Ref" Visible="True" DataField="BookingRef" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField HeaderText="Name" DataField="Name" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField HeaderText="Booking Time" DataField="BookingTime" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="TelNo" HeaderText="Tel No" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Communication Method" HeaderText="Contact Method" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Current Status" HeaderText="Booking Status" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Technician" HeaderText="Technician" NullDisplayText="No Technician Assigned" ReadOnly="True" >
                                    </asp:BoundField>
                                    <asp:TemplateField ItemStyle-Width="40px">
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                        <%----%>
                        
                                        <HeaderTemplate>
                                            <asp:CheckBox ID="SelectCheckBox" runat="server" ClientIDMode="Static" onclick="CheckAllEmp(this);" />
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkEmp" runat="server" oncheckedchanged="chkEmp_CheckedChanged"></asp:CheckBox>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    </asp:TemplateField>
                                </Columns>
                                <EditRowStyle BorderStyle="None" Width="100px" BackColor="#999999" />
                                <EmptyDataTemplate>There is no data visible</EmptyDataTemplate>
                                <FooterStyle BackColor="#CC6699" Height="40px" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="#CC6699" Height="40px" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BorderStyle="None" BackColor="#F5F5F5" ForeColor="#284775" />
                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                            </asp:GridView>
                            </p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12">
                            <p class="text-center">
                                <asp:Button ID="btnNew" runat="server" Enabled="false" Text="Mark New" CssClass="btn btn-left" onclick="MarkNew_Click" />
                                <asp:Button ID="btnApproved" runat="server" Enabled="false"  Text="Mark Approve" CssClass="btn btn-left" onclick="MarkApproved_Click" />
                                <asp:Button ID="btnCompleted" runat="server" Enabled="false" Text="Mark Complete" CssClass="btn btn-left" onclick="MarkCompleted_Click" />
                                <asp:Button ID="btnDeleted" runat="server" Enabled="false" Text="Mark Delete" CssClass="btn btn-left" onclick="MarkDeleted_Click" />
                            </p>
                        </div>
                    </div>
                </ContentTemplate>
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlBookingType" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="chkEmp" EventName="CheckedChanged" />
            <asp:AsyncPostBackTrigger ControlID="btnNew" EventName="Click" />        
            <asp:AsyncPostBackTrigger ControlID="btnApproved" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnCompleted" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnDeleted" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>

    I want it to call this function:

    protected void chkEmp_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkTest = (CheckBox)sender;
            GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
            int count = 0;
    
            foreach (GridViewRow gvrow in grdvBookings.Rows)
            {
                CheckBox chk = (CheckBox)gvrow.FindControl("chkEmp");
    
                if (chk.Checked)
                {
                    count++;
                }
            }
    
            if (count == 1)
            {
                btnNew.Enabled = true;
                btnApproved.Enabled = true;
                btnCompleted.Enabled = true;
                btnDeleted.Enabled = true;
            }
            else
            {
                btnNew.Enabled = false;
                btnApproved.Enabled = false;
                btnCompleted.Enabled = false;
                btnDeleted.Enabled = false;
            }
        }

    Any ideas on how to get around it?

    Thanks

    Rob

    Monday, January 16, 2017 12:29 PM

All replies

  • User-707554951 posted

    Hi Robbied81,

    Because your control is in the repeater control and it is out of scope to the Trigger collection. By the way you don't need to add trigger because your button control is already in the UpdatePanel, it will update when you click the button.

    Besides. Set AutoPostBack="true" for checkbox.

     <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <div class="row">
                        <div class="col-lg-2">Filter bookings by type:</div>
                        <div class="col-lg-4">
                            <asp:DropDownList ID="ddlBookingType" runat="server" onselectedindexchanged="ddlBookingType_SelectedIndexChanged" AutoPostBack="True" class="form-control"> 
                                <asp:ListItem Value="6" Selected="True">Choose...</asp:ListItem> 
                                <asp:ListItem Value="0">All Bookings</asp:ListItem>
                                <asp:ListItem Value="1">New Bookings</asp:ListItem>
                                <asp:ListItem Value="2">Approved Bookings</asp:ListItem>
                                <asp:ListItem Value="3">Completed Bookings</asp:ListItem>
                                <asp:ListItem Value="4">Deleted Bookings</asp:ListItem>
                                <asp:ListItem Value="5">Future Bookings</asp:ListItem>
                            </asp:DropDownList>
                        </div>
                        <div class="col-lg-6"></div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2">
                        </div>
                        <div class="col-lg-10">
                            <p>
                            <asp:GridView ID="grdvBookings" ClientIDMode="Static" runat="server" CssClass="gridview" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="True" DataKeyNames="BookingID,BookingRef" CellPadding="10" GridLines="None" >
                                <PagerSettings PageButtonCount="10" />
                                <PagerStyle cssClass="Test"/>
                                <RowStyle BorderStyle="None" BackColor="#FFFFFF" HorizontalAlign="Center" ForeColor="#333333"></RowStyle>
                                <Columns>
                                    <asp:HyperLinkField Text="Click for more info"  DataNavigateUrlFormatString="~/Admin/Bookings/BookingDetails.aspx?BookingId={0}" HeaderText="Go To Booking" DataNavigateUrlFields="BookingRef" />
                                    <asp:BoundField HeaderText="Booking Ref" Visible="True" DataField="BookingRef" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField HeaderText="Name" DataField="Name" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField HeaderText="Booking Time" DataField="BookingTime" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="TelNo" HeaderText="Tel No" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Communication Method" HeaderText="Contact Method" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Current Status" HeaderText="Booking Status" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Technician" HeaderText="Technician" NullDisplayText="No Technician Assigned" ReadOnly="True" >
                                    </asp:BoundField>
                                    <asp:TemplateField ItemStyle-Width="40px">
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                        <%----%>
                        
                                        <HeaderTemplate>
                                            <asp:CheckBox ID="SelectCheckBox" runat="server"  ClientIDMode="Static" onclick="CheckAllEmp(this);" />
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkEmp" runat="server"  AutoPostBack="true" oncheckedchanged="chkEmp_CheckedChanged"></asp:CheckBox>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    </asp:TemplateField>
                                </Columns>
                                <EditRowStyle BorderStyle="None" Width="100px" BackColor="#999999" />
                                <EmptyDataTemplate>There is no data visible</EmptyDataTemplate>
                                <FooterStyle BackColor="#CC6699" Height="40px" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="#CC6699" Height="40px" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BorderStyle="None" BackColor="#F5F5F5" ForeColor="#284775" />
                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                            </asp:GridView>
                            </p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12">
                            <p class="text-center">
                                <asp:Button ID="btnNew" runat="server" Enabled="false" Text="Mark New" CssClass="btn btn-left" onclick="MarkNew_Click" />
                                <asp:Button ID="btnApproved" runat="server" Enabled="false"  Text="Mark Approve" CssClass="btn btn-left" onclick="MarkApproved_Click" />
                                <asp:Button ID="btnCompleted" runat="server" Enabled="false" Text="Mark Complete" CssClass="btn btn-left" onclick="MarkCompleted_Click" />
                                <asp:Button ID="btnDeleted" runat="server" Enabled="false" Text="Mark Delete" CssClass="btn btn-left" onclick="MarkDeleted_Click" />
                            </p>
                        </div>
                    </div>
                </ContentTemplate>
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlBookingType" EventName="SelectedIndexChanged" />
           <%-- <asp:AsyncPostBackTrigger ControlID="chkEmp" EventName="CheckedChanged" />--%>
            <asp:AsyncPostBackTrigger ControlID="btnNew" EventName="Click" />        
            <asp:AsyncPostBackTrigger ControlID="btnApproved" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnCompleted" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnDeleted" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel

    Best Regards

    Cathy

    Tuesday, January 17, 2017 7:02 AM
  • User940894612 posted

    Hi

    The point is the button remains disabled until the a checkbox is checked.  Unfortunately adding postback = true does not work.

    Thanks

    Rob

    Tuesday, January 17, 2017 9:00 AM
  • User-707554951 posted

    Hi Robbied81,

    Following is an working sample. you could refer to it:

          <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <div class="row">
                        <div class="col-lg-2">Filter bookings by type:</div>
                        <div class="col-lg-4">
                            <asp:DropDownList ID="ddlBookingType" runat="server"  AutoPostBack="True" class="form-control"> 
                                <asp:ListItem Value="6" Selected="True">Choose...</asp:ListItem> 
                                <asp:ListItem Value="0">All Bookings</asp:ListItem>
                                <asp:ListItem Value="1">New Bookings</asp:ListItem>
                                <asp:ListItem Value="2">Approved Bookings</asp:ListItem>
                                <asp:ListItem Value="3">Completed Bookings</asp:ListItem>
                                <asp:ListItem Value="4">Deleted Bookings</asp:ListItem>
                                <asp:ListItem Value="5">Future Bookings</asp:ListItem>
                            </asp:DropDownList>
                        </div>
                        <div class="col-lg-6"></div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2">
                        </div>
                        <div class="col-lg-10">
                            <p>
                            <asp:GridView ID="grdvBookings" ClientIDMode="Static" runat="server" CssClass="gridview" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="True"  CellPadding="10" GridLines="None" >
                                <PagerSettings PageButtonCount="10" />
                                <PagerStyle cssClass="Test"/>
                                <RowStyle BorderStyle="None" BackColor="#FFFFFF" HorizontalAlign="Center" ForeColor="#333333"></RowStyle>
                                <Columns>
                                    <asp:HyperLinkField Text="Click for more info"  DataNavigateUrlFormatString="~/Admin/Bookings/BookingDetails.aspx?BookingId={0}" HeaderText="Go To Booking"/>
                                    <asp:BoundField HeaderText="Booking Ref" Visible="True" DataField="Drug" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField HeaderText="Name" DataField="Drug" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField HeaderText="Booking Time" DataField="Drug" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Drug" HeaderText="EmailAddress" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Drug" HeaderText="Tel No" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Drug" HeaderText="Contact Method" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Drug" HeaderText="Booking Status" ReadOnly="true" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Drug" HeaderText="Technician" NullDisplayText="No Technician Assigned" ReadOnly="True" >
                                    </asp:BoundField>
                                    <asp:TemplateField ItemStyle-Width="40px">
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                        <%----%>
                        
                                        <HeaderTemplate>
                                            <asp:CheckBox ID="SelectCheckBox" runat="server" ClientIDMode="Static" onclick="CheckAllEmp(this);" />
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkEmp" runat="server"  OnCheckedChanged="chkEmp_CheckedChanged1" AutoPostBack="true"></asp:CheckBox>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                    </asp:TemplateField>
                                </Columns>
                                <EditRowStyle BorderStyle="None" Width="100px" BackColor="#999999" />
                                <EmptyDataTemplate>There is no data visible</EmptyDataTemplate>
                                <FooterStyle BackColor="#CC6699" Height="40px" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle BackColor="#CC6699" Height="40px" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BorderStyle="None" BackColor="#F5F5F5" ForeColor="#284775" />
                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                            </asp:GridView>
                            </p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12">
                            <p class="text-center">
                                <asp:Button ID="btnNew" runat="server" Enabled="false" Text="Mark New" CssClass="btn btn-left"  />
                                <asp:Button ID="btnApproved" runat="server" Enabled="false"  Text="Mark Approve" CssClass="btn btn-left" />
                                <asp:Button ID="btnCompleted" runat="server" Enabled="false" Text="Mark Complete" CssClass="btn btn-left"/>
                                <asp:Button ID="btnDeleted" runat="server" Enabled="false" Text="Mark Delete" CssClass="btn btn-left"/>
                            </p>
                        </div>
                    </div>
                </ContentTemplate>
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlBookingType" EventName="SelectedIndexChanged" />
        <%--    <asp:AsyncPostBackTrigger ControlID="chkEmp" EventName="CheckedChanged" />--%>
            <asp:AsyncPostBackTrigger ControlID="btnNew" EventName="Click" />        
            <asp:AsyncPostBackTrigger ControlID="btnApproved" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnCompleted" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnDeleted" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>

    Code behind:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataTable table = new DataTable();
                    table.Columns.Add("Dosage", typeof(int));
                    table.Columns.Add("Drug", typeof(string));
                    table.Columns.Add("Patient", typeof(string));
                    table.Columns.Add("Date", typeof(DateTime));
    
                    // Here we add five DataRows.
                    table.Rows.Add(25, "Indocin", "David", DateTime.Now);
                    table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
                    table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
                    table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
                    table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
                    grdvBookings.DataSource = table;
                    grdvBookings.DataBind();
                }
            }
          
    
            protected void chkEmp_CheckedChanged1(object sender, EventArgs e)
            {
                CheckBox chkTest = (CheckBox)sender;
                GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
                int count = 0;
    
                foreach (GridViewRow gvrow in grdvBookings.Rows)
                {
                    CheckBox chk = (CheckBox)gvrow.FindControl("chkEmp");
    
                    if (chk.Checked)
                    {
                        count++;
                    }
                }
    
                if (count == 1)
                {
                    btnNew.Enabled = true;
                    btnApproved.Enabled = true;
                    btnCompleted.Enabled = true;
                    btnDeleted.Enabled = true;
                }
                else
                {
                    btnNew.Enabled = false;
                    btnApproved.Enabled = false;
                    btnCompleted.Enabled = false;
                    btnDeleted.Enabled = false;
                }
    
            }


    Best regards

    Cathy

    Saturday, January 21, 2017 7:10 AM
  • User465171450 posted

    chkEmp is in an itemtemplate. It's not a discrete control and in this case can't be an update trigger. The grid can be an update trigger since it's the container for the chkEmp checkbox.

    Sunday, January 22, 2017 2:32 AM