Avatar of cdlciddit
cdlciddit

asked on 

Why do I get the error Exception Details: System.ArgumentException: A ControlID must be specified in ControlParameter ''. When it is specified

Hello. I'm trying to have 2 searches on one page.   When I use this code both searches work fine:

<%--<%@ Page Title="" Language="VB" MasterPageFile="~/Layout.master" AutoEventWireup="false" CodeFile="providerSearch.aspx.vb" Inherits="SchoolPsychology_tbi_providerSearch" %>--%>
<%@ Page Language="VB" MasterPageFile="~/SchoolPsychology/RPR.master" Title="Providers Search Page" CodeFile="~/SchoolPsychology/tbi/providerSearch.aspx.vb" Inherits="SchoolPsychology_tbi_providerSearch"%>
<%@ MasterType TypeName="CIDD.MasterPage" %>

<%@ Import Namespace="DbConduit.Db" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Register TagPrefix="ig" TagName="rprContacts" Src="~/SchoolPsychology/rprContacts_tbi.ascx" %>



<asp:Content ID="Content2" ContentPlaceHolderID="Content" Runat="Server">
    Search for Providers by County or Last Name<br />
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" Text="Search Providers by County" />
    <br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." EnableModelValidation="True" ForeColor="#333333" GridLines="None" AllowPaging="true">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:BoundField DataField="Last_name" HeaderText="Last Name" SortExpression="Last_name" />
            <asp:BoundField DataField="First_name" HeaderText="First Name" SortExpression="First_name" />
            <asp:BoundField DataField="County" HeaderText="County" SortExpression="County" />
            <asp:BoundField DataField="Employer" HeaderText="Employer" SortExpression="Employer" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
        </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TBIConnectionString %>" FilterExpression="[County] LIKE '%{0}%'" SelectCommand="SELECT [Last name] AS Last_name, [First name] AS First_name, [County], [Employer/School System] AS Employer, [Email], [Phone] FROM [Providers]">
        <FilterParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="County" PropertyName="Text" Type="String" DefaultValue="1" />
        </FilterParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;&nbsp;
    <asp:Button ID="Button2" runat="server" Text="Search Providers by Last Name" />
    <br />
     <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource2" EmptyDataText="There are no data records to display." EnableModelValidation="True" ForeColor="#333333" GridLines="None">
         <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
         <Columns>
             <asp:BoundField DataField="Last_name" HeaderText="Last_name" SortExpression="Last_name" />
             <asp:BoundField DataField="First_name" HeaderText="First_name" SortExpression="First_name" />
             <asp:BoundField DataField="County" HeaderText="County" SortExpression="County" />
             <asp:BoundField DataField="column1" HeaderText="column1" SortExpression="column1" />
             <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
             <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
         </Columns>
         <EditRowStyle BackColor="#999999" />
         <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
         <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
         <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
         <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TBIConnectionString %>" SelectCommand="SELECT [Last name] AS Last_name, [First name] AS First_name, [County], [Employer/School System] AS column1, [Email], [Phone] FROM [Providers] WHERE ([Last name] LIKE '%' + @Last_name + '%')">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox2" Name="Last_name" PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <br />
</asp:Content>

Open in new window


But when I try to change the 2nd datasource to include the filter expression attribute and the <FilterParameters> and the <asp:ControlParameter> Then I get the error: Exception Details: System.ArgumentException: A ControlID must be specified in ControlParameter ''.
I'm sure I specify the ID here is the code where I specify the ID:

<FilterParameters>
            <asp:ControlParameter ControlID="TextBox2" Name="Last_name" PropertyName="Text" Type="String" DefaultValue="1" />
        </FilterParameters>

Open in new window


This is all the code on that page that gives me the error after I change the datasource to include the
FilterExpression="[County] LIKE '%{0}%'"

Open in new window

and I add this
<FilterParameters>
            <asp:ControlParameter ControlID="TextBox2" Name="Last_name" PropertyName="Text" Type="String" DefaultValue="1" />
        </FilterParameters>

Open in new window


Here is all the code that doesn't work
<%--<%@ Page Title="" Language="VB" MasterPageFile="~/Layout.master" AutoEventWireup="false" CodeFile="providerSearch.aspx.vb" Inherits="SchoolPsychology_tbi_providerSearch" %>--%>
<%@ Page Language="VB" MasterPageFile="~/SchoolPsychology/RPR.master" Title="Providers Search Page" CodeFile="~/SchoolPsychology/tbi/providerSearch.aspx.vb" Inherits="SchoolPsychology_tbi_providerSearch"%>
<%@ MasterType TypeName="CIDD.MasterPage" %>

<%@ Import Namespace="DbConduit.Db" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Register TagPrefix="ig" TagName="rprContacts" Src="~/SchoolPsychology/rprContacts_tbi.ascx" %>



<asp:Content ID="Content2" ContentPlaceHolderID="Content" Runat="Server">
    Search for Providers by County or Last Name<br />
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" Text="Search Providers by County" />
    <br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." EnableModelValidation="True" ForeColor="#333333" GridLines="None" AllowPaging="true">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:BoundField DataField="Last_name" HeaderText="Last Name" SortExpression="Last_name" />
            <asp:BoundField DataField="First_name" HeaderText="First Name" SortExpression="First_name" />
            <asp:BoundField DataField="County" HeaderText="County" SortExpression="County" />
            <asp:BoundField DataField="Employer" HeaderText="Employer" SortExpression="Employer" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
        </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TBIConnectionString %>" FilterExpression="[County] LIKE '%{0}%'" SelectCommand="SELECT [Last name] AS Last_name, [First name] AS First_name, [County], [Employer/School System] AS Employer, [Email], [Phone] FROM [Providers]">
        <FilterParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="County" PropertyName="Text" Type="String" DefaultValue="1" />
        </FilterParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;&nbsp;
    <asp:Button ID="Button2" runat="server" Text="Search Providers by Last Name" />
    <br />
     <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource2" EmptyDataText="There are no data records to display." EnableModelValidation="True" ForeColor="#333333" GridLines="None">
         <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
         <Columns>
             <asp:BoundField DataField="Last_name" HeaderText="Last_name" SortExpression="Last_name" />
             <asp:BoundField DataField="First_name" HeaderText="First_name" SortExpression="First_name" />
             <asp:BoundField DataField="County" HeaderText="County" SortExpression="County" />
             <asp:BoundField DataField="column1" HeaderText="column1" SortExpression="column1" />
             <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
             <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
         </Columns>
         <EditRowStyle BackColor="#999999" />
         <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
         <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
         <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
         <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TBIConnectionString %>"  FilterExpression="[County] LIKE '%{0}%'"  SelectCommand="SELECT [Last name] AS Last_name, [First name] AS First_name, [County], [Employer/School System] AS column1, [Email], [Phone] FROM [Providers]">
        <FilterParameters>
            <asp:ControlParameter ControlID="TextBox2" Name="Last_name" PropertyName="Text" Type="String" DefaultValue="1" />
        </FilterParameters>
    </asp:SqlDataSource>
    <br />
    <br />
</asp:Content>

Open in new window

Visual Basic.NETASP.NET.NET Programming

Avatar of undefined
Last Comment
Vikram Singh Saini

8/22/2022 - Mon