Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Accessing first control of the FormView
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
OS:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01325311
Message ID:
01327690
Vues:
11
>>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.

Just in case, here is the interesting technique for obtaining ClientID of any control:

http://forums.asp.net/t/889146.aspx
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform