Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Database
Database General Discussion
why doesn't FindControl also work on user controls?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="psykik, post: 33332, member: 2101"] I'm going totally nuts here. I hope someone can help me here, I've been going nuts for 2 days now. I have a page where I update and insert items. (for this particular website it's horses.) Each horse has a lot of properties. I made user controls for all properties. all user controls contain a simple dropdownlist with inside: value: an integer (FK to the property table inside the database) display: the name of the property being read out the db also before databinding the dropdownlist with values out of the db I've got a hard coded one : "NOT AVAILABLE". Not available will basically insert NULL inside the database row. for inserting horses, I simply put an html table inside a panel and put textareas, textbox, and all the user controls there. (I can thus call all these controls directly in my code-behind file) INSERTING works perfectly. It's the updating part that is making me go nuts: I now use these user controls as templatefields inside a formview (or detailview, I tried both) for the updating part. here's a small example: for inserting, an click-event is fired on the button "new" all my values are checked or replaced: [code]Dim ras As Object = RaceSelect1.SelectedRace If Not ras.ToString = String.Empty Then ras = CInt(RaceSelect1.SelectedRace) Else ras = sqlintnull End If[/code] here if in my usercontrol, I selected a race that is in the db then it will use that value. if instead "not available" is selected, the value for "not available" is empty and so a variable sqlintnull is entered. this @ras is then used as a parameter for my stored procedure. I do this for about 15 parameters. this work perfectly because these controls are not inside a detailview of formview. for updating (the information is thus already in the db) I want to display it in a formview of detailview. but if the user clicks "edit" he must be able to change the values. when in edit mode if the user chooses "not available" in the usercontrol dropdownlist I get an [B]invalid cast to error[/B] because inside the dropdownlist it's a STRING and not DBNULL. this is why I need : [code]Dim ras As Object = RaceSelect1.SelectedRace If Not ras.ToString = String.Empty Then ras = CInt(RaceSelect1.SelectedRace) Else ras = sqlintnull End If[/code] but here instead as in inserted: [code]Dim RaceSelect1 as UserControl = CType(Formview1.FindControl("RaceSelect1"), UserControl) Dim ras As Object = [B]RaceSelect1.SelectedRace[/B] If Not ras.ToString = String.Empty Then ras = CInt(RaceSelect1.SelectedRace) Else ras = sqlintnull End If[/code] (the bold doesn't work!, I cannot seem to get into my public property meaning it doesn't recognises the user control) :( :( ok then I tried this: I replaced 1 usercontrol with a plain dropdownlist linked to a sqldataconnection. if I then go to the code behind : (didn't put all the code, just the logic here ) ... [code]formview1.findcontrol("dropdownlistname")[/code] and then [code]dropdownlistname.selectedvalue[/code] [B]it works [/B] so why doesn't this also work on user controls ... [code]formview1.findcontrol("usercontrolname") usercontrolname.publicmethodname[/code] what's the use of usercontrols if this doesn't work :( :( any help would be great thank you [/QUOTE]
Insert quotes…
Verification
Post reply
Database
Database General Discussion
why doesn't FindControl also work on user controls?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom