Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Accessing first control of the FormView
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01325311
Message ID:
01325402
Views:
14
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I have a FormView with UserControls inside. I want to be able to set focus to the FirstControl in the FormView (BTW, this control in the ReadOnly mode).
>
>I tried
>
>TextBox txt = currentForm.Row.FindControl("txtFirstName") as TextBox;
>            if (txt != null)
>                txt.Focus();
>            else
>                currentForm.Row.Focus();
>
>txtFirstName is a first control in the General User Info user control.

You can't access a control inside of a user control this way. Inside of the formview, FindControl can only find the name of the user control. FindControl is not recursive - it doesn't drill into contained control collections. I would suggest changing your user control to expose a method which allows you to set focus to this control. Then use code similar to what you're doing above to find your user control instead. Once you've found it, call this method.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform