Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Could not find control - in ControlParameter -

Posted on 2006-06-28
5
Medium Priority
?
642 Views
Last Modified: 2008-01-09
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:webtoolConn %>" >
    <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.RepeaterCommandEventArgs) Handles rptEditProject.ItemCommand

Dim projectId As String = Request.QueryString("projectId")

dsEditProject.UpdateCommand = "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
0
Comment
Question by:donaldcroswell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 16999152
change
        <asp:ControlParameter ControlID="txtProjectName" PropertyName="Textbox.Text" Name="projectName" Type="String" />
To
        <asp:ControlParameter ControlID="txtProjectName" PropertyName="Text" Name="projectName" Type="String" />

HTH
0
 
LVL 9

Expert Comment

by:bele04
ID: 16999331
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##$txtProjectName" (the ## dpends on what row of the control you're editing...ie. row2 = Repeater1$ctl02$txtProjectName) 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...
0
 

Author Comment

by:donaldcroswell
ID: 17006025
so how do I set the value of the parameter to be the value in the box?

<asp:Parameter Name="projectName" Type="String" />
0
 
LVL 9

Accepted Solution

by:
bele04 earned 2000 total points
ID: 17006249
you can set it in your before you call the update method of your sqldatasource...something like this:

[ASPX File]
...
<UpdateParameters>
        <asp:Parameter Name="projectName" Type="String" />
    </UpdateParameters>
...

[code behind]

Protected Sub rptEditProject_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rptEditProject.ItemCommand

Dim projectId As String = Request.QueryString("projectId")

dsEditProject.UpdateCommand = "UPDATE [projects] SET [projectName] = @projectName WHERE [projectId] = " & projectId & ";"
dsEditProject.UpdateParameters("projectName").DefaultValue = CType(Repeater1.Items(e.Item.ItemIndex).FindControl("txtProjectName"), TextBox).Text
dsEditProject.Update()

End Sub
0
 

Author Comment

by:donaldcroswell
ID: 17006284
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!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question