Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 24, 2011 07:52 AM by xiaohua
Mar 28, 2006 05:37 PM|LINK
I don't know but this is a really simple error. When I create a hyperlink or any object in the html, and try to use it in the code behind, it says
name 'objectName' is not declared. When I try to use say a label in the codebehind lblTest, after I put a .(dot) after it, the property and methods list should pop up, but it doesnt since object is not recognized. I don't have a problem with
all the other objects that were previously created, just the ones that I add now aren't being recognized. In the previous versions of visual studio, the controls were added at the top after the line:
For example, if I had a label control in the html part named lblTest, it would place the following line in the code behind:
However, this is not seen in the 2005 version. Is that the reason the conrol is not being recognized?...Do I have to explicitly place these lines of code for every control I add to the page? It doesnt seem like it since all the other controls that I previously
created on this page don't have these lines of code and I can access them. Thanks for your help,
Mar 28, 2006 11:52 PM|LINK
VS 2005 uses partial class model one of the benefits of which is that you don't have to declare controls twice. It is sufficient to declare control in markup and declaration will be generated automatically. You don't see generated code, code file only contains
'user code'. It is difficult to say what is wrong, but please verify that
1. Control has runat="server".
2. Control ID is correctly spelled.
3. Control is in the <form runat="server">.
Mar 29, 2006 03:21 PM|LINK
I've checked all the points that you mentioned and I have those set up correctly. Any other ideas as to what might be causing this? Thanks
Mar 29, 2006 05:08 PM|LINK
Mar 29, 2006 05:48 PM|LINK
HTML code is as follows:
Everything was working fine and I could access anything, but I added another link within the repeater control, which I've marked in bold:
Text="Click here to see more documents and resources for this lesson"></asp:hyperlink>
In the code benind, this is the only one I can't access (it gives me error saying hpSubTitles is undeclared. The code behind is as follows:
repeaterLessonPlans.DataSource = myCourse.GetAllLessonPlans(course_id)
Then I have the following procedure defined in which I'm trying to access the hpSubTitles along with other code that I didn't post since it's long and not relative to the error I'm getting. I'm
just trying to set up the navigateUrl property for the hpSubTitles as shown below, but it doesn't let me.
Public Sub lesson_plan_onItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
Mar 29, 2006 06:37 PM|LINK
This looks like VS 2003 style code behind file. Did you migrate your Web before using it in VS 2005?
First I notice that Partial keyword is missing before the class declaration. Partial is very important as it tells compiler that some declarations and code will be coming from elsewhere (such as from markup). Without partial
control declarations won't be picked by intellisense. Here is how class looks when I create a new Web Form in VS 2005
I think adding partial will fix the intellisense problem, but I would recommend migrating Web site to the VS 2005 model or installing Web Application Project add-on as there might be other issues as well. For instance, InitializeComponent
is no longer used.
Mar 29, 2006 06:45 PM|LINK
I actually created this application in 2005 version, and I changed the class to have Public because I was trying to test something. However, even though I had partial class, it still does not recognize the controls.
Mar 29, 2006 08:26 PM|LINK
That's odd since only VS 2003 adds these:
content="Microsoft Visual Studio.NET 7.0"
Anyway, try adding a new, empty, default page, drop a button on it and see if it is available for intellisense in the code file.
Mar 29, 2006 09:04 PM|LINK
Yes, any new page I create lets me access the controls and brings up the intellisense. It's just with any new controls I add on a current page. It's also weird that it works when I make the class Public and add the following line of code after the
Mar 29, 2006 09:34 PM|LINK
If you add explicit declaration, it will definitely work, but that is what partial class architecture is supposed to do. VS 2005 does not support code behind model using full classes (at least not out of the box - you'll need Web Application Project add-on).
I would recommend creating a new Web for with code separation and moving code and element to the new page. Remember, you don't have declare them and you don't need initialize component and no need to add META elements from VS 2003.