Could not find control 'x' in ControlParameter 'y'
Asked Answered
D

2

5

I'm trying to filter results using a dropdownlist for my listview.

I have altered the select query for the datasource as follows...

The listview:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/ASPNetDB.mdb" 
        SelectCommand="SELECT * FROM [tblNames] WHERE Surnames=@Surnames">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="Surnames" 
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:AccessDataSource>

The dropdownlist:

<asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="AccessDataSource2" DataTextField="Genre" 
        DataValueField="NameID" AppendDataBoundItems="true">
            <asp:ListItem Value="" Selected ="True" >All Surnames</asp:ListItem>
</asp:DropDownList>

    <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/ASPNetDB.mdb" SelectCommand="SELECT * FROM [tblSurnames]">
    </asp:AccessDataSource>

The correct Control name is used (the exact same caps as well), but the page on load returns Could not find control 'DropDownList1' in ControlParameter 'Surnames'.

Any suggestions on what I'm doing wrong here?

EDIT: Here is the stack trace if it helps

[InvalidOperationException: Could not find control 'DropDownList1' in ControlParameter 'Surname'.]
   System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +2107838
   System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +50
   System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +113
   System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +46
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnLoadComplete(EventArgs e) +9010786
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2350
Delia answered 28/11, 2012 at 17:12 Comment(4)
Are the AccessDataSource and the DropDownList in different naming containers?Enstatite
They are in two different ContentPlaceHolders within the same page.Delia
Then the ControlID needs to be prefixed with the ID of the ContentPlaceHolder which contains the DropDownList: https://mcmap.net/q/2033579/-is-it-possible-to-use-a-control-in-a-different-content-tag-as-a-parameterEnstatite
@RichardDeeming: You should answer this thread, your answer is correct.Delia
E
8

The ControlID needs to be prefixed with the ID of the ContentPlaceHolder which contains the DropDownList:

<asp:ControlParameter 
   Name="Surnames" 
   ControlID="ContentPlaceholderID$DropDownList1" 
   PropertyName="SelectedValue" 
/>

See also: https://mcmap.net/q/2033579/-is-it-possible-to-use-a-control-in-a-different-content-tag-as-a-parameter

Enstatite answered 29/11, 2012 at 17:41 Comment(1)
I found that if the control is nested within multiple elements you have to specify them all, so I ended up with something like: YourContentPlaceHolder$YourASPxCallbackPanel$YourASPxPopupControl$YourASPxComboBoxPatrolman
D
0

Additionally, make sure your control of interest has runat="server". Argh.

Defection answered 10/7, 2017 at 19:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.