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
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
How are you adding these to the FormView control? Are you adding them as EditTemplates.
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.FindContr ol("Table1 ");
MultiView mv = (MultiView)FormView1.FindC ontrol("Mu ltiView1") ;
View vw = (View)FormView1.FindContro l("View1") ;
Thanlks
P.Ramprathap
Table tbl = (Table)FormView1.FindContr
MultiView mv = (MultiView)FormView1.FindC
View vw = (View)FormView1.FindContro
Thanlks
P.Ramprathap
ASKER
Thanks for the suggestion!
I'm not sure how litteral to be so I've tried multiple variations of your suggestions:
(MultiView)FormView1.FindC ontrol("Mu ltiView1") Yields the error message Syntax Error
FormView1.FindControl(Mult iView1) Yields the error message Multiview1 not declared
FormView1.FindControl("Mul tiView1") 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.
I'm not sure how litteral to be so I've tried multiple variations of your suggestions:
(MultiView)FormView1.FindC
FormView1.FindControl(Mult
FormView1.FindControl("Mul
Could you please post the code your using .
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Dim MView As MultiView = CType(FormView1.FindContro l("MultiVi ew1"),Mult iView)
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
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
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.
ASKER
That was great! Thank you.