0

Error: Could not find control 'mytextfield' in ControlParameter 'mycontrolparam'.

<asp:ControlParameter ControlID="mytextfield" Name="mycontrolparam" PropertyName="Text" Type="Int32" />

The error is because "mytextfield" is inside a panel control and I would need FindControl method to find it. But I want to find a quick solution if there is any, how to make mytextfield visible to the control parameter. The same code works on a different page but not on this one. Please keep in mind, I want to make minimum changes to the existing code.

Here is similar code I copied over from Microsoft site.

<asp:SqlDataSource id="Employees" runat="server"
  ConnectionString="<%$ ConnectionStrings:Northwind%>"
  SelectCommand="SELECT LastName FROM Employees WHERE Title = @Title">
  <SelectParameters>
    <asp:ControlParameter Name="Title" 
      ControlID="DropDownList1"
      PropertyName="SelectedValue"/>
  </SelectParameters>
</asp:sqldatasource>

Want to mention: 'mytextfield' is a readonly textfield. It does work OK on the other page though.

TheTechGuy
  • 16,560
  • 16
  • 115
  • 136

2 Answers2

0

Please add control parameter inside your codebehind page when sqldatasource is selecting. You will have to cast control first and then add parameters value. I assumed textbox xyz control inside panel named mypanel.

Protected Sub Employees_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles Employees.Selecting
            Dim xyz As TextBox = DirectCast(mypanel.findcontrol("yourcontrolname"), TextBox)
            Dim mycontrolparam = New SqlParameter("@mycontrolparam",xyz.text)
            e.Command.Parameters.Add(mycontrolparam)
        End Sub
Mitul
  • 9,734
  • 4
  • 43
  • 60
  • Thank you for the answer. Investigating http://forums.asp.net/t/940975.aspx/1?Could+not+find+control+xxx+in+ControlParameter+yyy+ right now. I can convert this to C# code but looking for a solution in .aspx file right now. – TheTechGuy Aug 01 '11 at 18:53
0

Myself: If a control is embedded inside a panel, you can only find it through FindControl method of that panel. It still actually did not work for me and I had to abandon it and use a a different method.

Use the following method otherwise

FindControl("MyControlID")
TheTechGuy
  • 16,560
  • 16
  • 115
  • 136