donaldcroswell
asked on
Could not find control - in ControlParameter -
Hello All
I have a repeater with controls, some draw from different SqlDatasources.
Everything loads up properly, I click my update button and then I get the error:
"Could not find control 'txtProjectName' in ControlParameter 'projectName'"
The Control txtProjectName is in the repeater <itemTemplate>
<asp:TextBox ID="txtProjectName" runat="server" Text='<%# DataBinder.Eval(Container. DataItem, "projectName") %>' />
My Datasource that I want to update looks like this:
<asp:SqlDataSource ID="dsEditProject" runat="server" ConnectionString="<%$ ConnectionStrings:webtoolC onn %>" >
<UpdateParameters>
<asp:ControlParameter ControlID="txtProjectName" PropertyName="Textbox.Text " Name="projectName" Type="String" />
</UpdateParameters>
My code behind looks like this:
Protected Sub rptEditProject_ItemCommand (ByVal source As Object, ByVal e As System.Web.UI.WebControls. RepeaterCo mmandEvent Args) Handles rptEditProject.ItemCommand
Dim projectId As String = Request.QueryString("proje ctId")
dsEditProject.UpdateComman d = "UPDATE [projects] SET [projectName] = @projectName WHERE [projectId] = " & projectId & ";"
dsEditProject.Update()
End Sub
It gets to the dsEditProject.Update and errors saying it can't find the control. If I hard code the "@projectName" in the update command everything works. It just isn't setting the parameterControl to what is in the textbox.
Also, if I set the parameter with asp:parameter it will put in whatever I put as the default.
How do I get the controlParameter to grab what is in txtProjectName?
Many thanks
Don
I have a repeater with controls, some draw from different SqlDatasources.
Everything loads up properly, I click my update button and then I get the error:
"Could not find control 'txtProjectName' in ControlParameter 'projectName'"
The Control txtProjectName is in the repeater <itemTemplate>
<asp:TextBox ID="txtProjectName" runat="server" Text='<%# DataBinder.Eval(Container.
My Datasource that I want to update looks like this:
<asp:SqlDataSource ID="dsEditProject" runat="server" ConnectionString="<%$ ConnectionStrings:webtoolC
<UpdateParameters>
<asp:ControlParameter ControlID="txtProjectName"
</UpdateParameters>
My code behind looks like this:
Protected Sub rptEditProject_ItemCommand
Dim projectId As String = Request.QueryString("proje
dsEditProject.UpdateComman
dsEditProject.Update()
End Sub
It gets to the dsEditProject.Update and errors saying it can't find the control. If I hard code the "@projectName" in the update command everything works. It just isn't setting the parameterControl to what is in the textbox.
Also, if I set the parameter with asp:parameter it will put in whatever I put as the default.
How do I get the controlParameter to grab what is in txtProjectName?
Many thanks
Don
since your textbox is inside your repeater tendency is that when .NET generates the html code for that it's client ID is changed to something like "Repeater1$ctl##$txtProjec tName" (the ## dpends on what row of the control you're editing...ie. row2 = Repeater1$ctl02$txtProject Name) that's why it can't find the textbox when it looks for the source of the controlparameter.
I suggest you just make it a parameter but if you insist on making it a controlparameter then you'll have to set a defaultvalue for it on your codebehind still and just assign the controlID to another control that it can find so it doesn't return an error. Up to now I still haven't found a way yet to dynamically assign a control to a controlparameter when it's inside a control like a datagrid or repeater and etc...
I suggest you just make it a parameter but if you insist on making it a controlparameter then you'll have to set a defaultvalue for it on your codebehind still and just assign the controlID to another control that it can find so it doesn't return an error. Up to now I still haven't found a way yet to dynamically assign a control to a controlparameter when it's inside a control like a datagrid or repeater and etc...
ASKER
so how do I set the value of the parameter to be the value in the box?
<asp:Parameter Name="projectName" Type="String" />
<asp:Parameter Name="projectName" Type="String" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! that worked great.
Actually the e.Item.ItemIndex gave me a out of range error but I just put in "0" as it only returns one row and that worked.
Cheerios!
Actually the e.Item.ItemIndex gave me a out of range error but I just put in "0" as it only returns one row and that worked.
Cheerios!
<asp:ControlParameter ControlID="txtProjectName"
To
<asp:ControlParameter ControlID="txtProjectName"
HTH