Link to home
Create AccountLog in
Avatar of browsen
browsen

asked on

Error "Name 'MyControlName' is not declared

I am creating my first ASP.net site and I am utilizing Visual Studio 2008 Professional Edition.

I am working with a form view control, a table, a multiview control, and several view controls.  

My desire is to place the view control inside the multiview control the multiview inside the table and the table inside the form view, however when I do this the code behind file is unable to locate the controls, specifically I receive the error message "Name 'My Control' is not declared".

All the code associated with the view and multiview controls work perfectly on their own it is only when these controls are placed within the form view control that I receive an error.

Any help would be appreciated; I should mention that my skill level and understanding of VB and ASP.Net is very low.

Thanks for your help!
Jason
Avatar of imateyelectronics
imateyelectronics
Flag of United States of America image

How are you adding these to the FormView control?  Are you adding them as EditTemplates.
Avatar of browsen
browsen

ASKER

I am selecting the form view control from the toolbox once this is placed on the page I select edit templates.  The template I have modified is the item template.  I have then placed the table, multiview, and view controls inside the template.  I then selected end template editing from the form control.
Please try accesing those controls like
Table tbl = (Table)FormView1.FindControl("Table1");
MultiView mv = (MultiView)FormView1.FindControl("MultiView1");
View vw = (View)FormView1.FindControl("View1");
 
Thanlks
P.Ramprathap
Avatar of browsen

ASKER

Thanks for the suggestion!

I'm not sure how litteral to be so I've tried multiple variations of your suggestions:
(MultiView)FormView1.FindControl("MultiView1")   Yields the error message Syntax Error
FormView1.FindControl(MultiView1)  Yields the error message Multiview1 not declared
 FormView1.FindControl("MultiView1")  Yields no errors however it does not appear to correct the existing errors.  By the way I allowed my controls to keep the default names, so my multiview control is named multiview1 etc.


Could you please post the code your using .
ASKER CERTIFIED SOLUTION
Avatar of imateyelectronics
imateyelectronics
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of browsen

ASKER

Dim MView As MultiView = CType(FormView1.FindControl("MultiView1"),MultiView)

This is exactly what I needed thank you!

Could you explain why this is neccesary and what exactly this is doing???

Thank you so much!
Jason
Avatar of browsen

ASKER

Thanks Again!!!
The reason why it is necessary is because the control is placed inside of a naming container.  Naming containers are controls such as the gridview, formview or detailsview.  When adding controls within them, we have to search for a control within a control to be able to access the controls properties.  This is when the findcontrol method comes in, it searches through a naming container and finds a control based off of the controlID.  I hope I explained that ok.  
Avatar of browsen

ASKER

That was great!  Thank you.