473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't access controls in code behind

I have a web project inVS2005 that I copied some existing pages from a
website that I previously created. To clarify the website was originally
created in Visual Web Developer Express and not I have created a web project
(not a website) in VS2005 and add a few of the pages to this web project
One of the pages I am currently working with is not allowing me to reference
the controls from the design page in the code behind. Do I need to make
some adjustments to the pages since they were originally in a website and
are now in a web project? Thanks for the help.
Sep 30 '06 #1
3 3564
Hi,

David A. Osborn wrote:
I have a web project inVS2005 that I copied some existing pages from a
website that I previously created. To clarify the website was originally
created in Visual Web Developer Express and not I have created a web project
(not a website) in VS2005 and add a few of the pages to this web project
One of the pages I am currently working with is not allowing me to reference
the controls from the design page in the code behind. Do I need to make
some adjustments to the pages since they were originally in a website and
are now in a web project? Thanks for the help.
You must add runat="server" to all the controls that you wish to access
from the code behind, and of course they must have an ID.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 1 '06 #2
Both of these items are included. I'm guessing it has something to do
with the fact that the files were originally in a website solution and
now that they are added to a web project, they are some how not tied
into the project properly.

Laurent Bugnion wrote:
Hi,

David A. Osborn wrote:
I have a web project inVS2005 that I copied some existing pages from a
website that I previously created. To clarify the website was originally
created in Visual Web Developer Express and not I have created a web project
(not a website) in VS2005 and add a few of the pages to this web project
One of the pages I am currently working with is not allowing me to reference
the controls from the design page in the code behind. Do I need to make
some adjustments to the pages since they were originally in a website and
are now in a web project? Thanks for the help.

You must add runat="server" to all the controls that you wish to access
from the code behind, and of course they must have an ID.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 2 '06 #3
Hi,

do********@hotm ail.com wrote:
Both of these items are included. I'm guessing it has something to do
with the fact that the files were originally in a website solution and
now that they are added to a web project, they are some how not tied
into the project properly.
In ASP.NET 2.0, the controls are added to the code-behind by using an
additional CS file named "ClassName.desi gner.cs", which contains a
partial class. In Website projects, this file is created automatically.
When you moved the files to the web application project, it might very
well be that the link has been broken.

You have two solutions: Add a new Web Form to your web app project and
copy the file (ASPX and CS) into the corresponding new files. This will
restore the link to the designer.cs file.

Another way is to simply declare the controls yourself in the code behind:

// For example
protected Button bnClickMe;

It is sufficient to declare them, they will be automatically
instantiated by the framework. Note that they must be declared protected .

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5320
by: theComputer7 | last post by:
I cut down the code to make this half way understandable... I have read Data Grid girls caution about over use of dynamic controls. I truly believe what I am doing requires dynamically inserted user controls. Worse I'm trying to add dynamic user controls from within a repeater loop (looping through attributes)... I bind to a function in the code behind and pass in the attribute. <asp:repeater id="rAttributes" Runat="server">
4
9810
by: Willy | last post by:
Hi All! I'm using Code-behind model for my ASP.NET pages. But to skip the compilation step, I reference my code-behind pages as follows... <%@ Page Language="VB" Debug="true" Src="~/code/MyTestPage.vb" %> It works beautifully. But how do I access the User Controls (non-compiled ASCX files) those are placed in my MyTestPage.aspx ?
5
1310
by: Steven | last post by:
I'm using C# as code-behind for my aspx pages. How can I bind pages.. so that both the pages can use the functions, variables, controls .. between each other. eg., if I declare function scope() in page1, I should be able to use it in page2 and vice-versa. same with variable also.. Any help would be grealty apprecited! Thanks
2
11412
by: fxs | last post by:
Hello, I have the following controls on an aspx page: 2 html radio button controls, 1 asp:label control and 1 asp:button control.... <INPUT id="rdo1" type="radio" name="grp1" onClick="clientsidecode();"> <INPUT id="rdo2" type="radio" name="grp1" checked onclick="clientsidecode();"> <asp:Label id="Label1" runat="server">Label</asp:Label> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
6
2343
by: Plamen Doykov | last post by:
Hi all I have converted a simple project from ASP.NET 1 to 2.0 with the latest prerelease of Visual Studio 2005. The problem is I can't access internal members from the code behind. It gives: error CS0122: 'Class' is inaccessible due to its protection level This happens only when access members from code behind, not from the other classes. It compiles OK when making the class and its members public. However, I don't want to do that....
7
2885
by: Alan Silver | last post by:
Hello, I am just looking at VWD and seeing what needs doing to take an existing site I've written by hand and importing it into VWD. I've already discovered that I need to rename my code-behind files to match the .aspx file name so VWD will tie the two together, and I'm now wondering what to do about the location of the code-behind files. Is there any set convention for where the code-behind files live? I have been putting them in the...
5
3170
by: Easystart | last post by:
Hi, Sorry for my English. English is not my native tougue. I am working in MS Access 2000 with a SQLServer 2000 Backend database. MS Access 2000 is my GUI front end that has SQLServer linked tables in it. One of my forms has two TEXT BOX controls formated as Short Date. The form is binded to a linked table. The linked tables has about 7 records and one of the control is binded to a table field. These two controls displays the date...
4
1892
by: jmacduff | last post by:
I have a set of pages ( about 10 ) that all have the same controls at the top, however I am unable to put the controls the master page for the site since the other 50 pages dont have the controls. Is there a way that I can define a common template / etc where this code can live 1 place and then I can just use it / insert it onto these ten pages? So for example if you wanted to put 4 text boxes on 10 pages with the 4 text boxes exactly...
0
899
by: anileshlakhtakia | last post by:
Hi, I am getting this problem and i am not able to understand what is the logic behind this.My Problem is i have 2 user controls on my application having same namespace lets say TestApplication.UI.View.UserControl (with the code behind classes UserControl1 and UserControl2*and i have a aspx page with the name space TestApplication.UI.View. From the aspx page i am able to access both the user controls by typing...
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.