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:
01325426
Vues:
12
>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.

I'm not sure I completely get the idea of exposing the method, would you please elaborate a bit?

Also I have multiple forms, so I named my UserControl (GeneralInfo) differently in each form. I currently have the following code:
 protected void ShowView(int row)
    {
        this.PeopleNoneForm.Visible = false;
        this.PeopleFriendsForm.Visible = false;
        this.PeopleVolunteersForm.Visible = false;
        this.PeopleBothForm.Visible = false;

        if (this.ProfilesGrid.SelectedIndex >= 0)
        {

            // then set one form to visible according to LetterCode

            clseditmode.editmode = true;
            clseditmode.firstload = true;

            string letterCode = ProfilesGrid.SelectedDataKey.Values["LetterCode"].ToString();
            FormView currentForm = new FormView() ;
            //this.PersonType = Convert.ToChar(letterCode);
            //ViewState["PersonType"] = this.PersonType; 
            switch (letterCode)
            {
                case "B":
                case "G":
                    this.PeopleFriendsForm.Visible = true;
                    currentForm = this.PeopleFriendsForm;
                    break;
                case "M":
                case "V":                
                    this.PeopleVolunteersForm.Visible = true;
                    //this.PeopleVolunteersForm.Row.Focus();
                    currentForm = this.PeopleVolunteersForm;
                    break;
                case "O":
                case "W":
                    this.PeopleBothForm.Visible = true;
                    //this.PeopleBothForm.Row.Focus(); 
                    currentForm = this.PeopleBothForm;
                    break;

                case "N":
                case "A":
                    this.PeopleNoneForm.Visible = true;
                    //this.PeopleNoneForm.Row.FindControl("txtFirstName"); 
                    currentForm = this.PeopleNoneForm;
                    break;

            }
            TextBox txt = currentForm.Row.FindControl("txtFirstName") as TextBox;
            if (txt != null)
                txt.Focus();
            else
                currentForm.Row.Focus();  
            //this.ProfilesGrid.Style.Add("display", "none"); 

        }
    }
So, as you see, I wanted to save some typing and instead of calling each individual form FindControl method have it outside the case switch loop. Not a bit deal to have it repeated, though.

And I think I got your idea while I was typing. You probably meant to add some method such as GetFirstControl() to my UserControl that would return my textbox...

See also http://forums.asp.net/p/1275256/2433928.aspx#2433928 I'm just thinking what is the best way to solve this particular problem in my situation...
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