Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code behind problem 1

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I have been building a simple ASP.NET application as an exercise. I have a single stand-alone .ASPX page with mixed HTML and in-line VB code. I have been using Visual Studio 2005 to edit the file which I had placed under an existing web site on the local host.

I decided that it was all getting a bit unwieldy and thought it was time to separate out the code. I initially attempted this using #includes but hit some problems. I then stumbled across the Code Behind concept. I therefore altered the line:
Code:
<%@ Page Language="VB" Debug="true" CompilerOptions='/R:"C:\Program Files\Microsoft.NET\Odbc.Net\Microsoft.data.odbc.dll"'%>
to
Code:
<%@ Page Language="VB" Debug="true" CompilerOptions='/R:"C:\Program Files\Microsoft.NET\Odbc.Net\Microsoft.data.odbc.dll"' CodeFile="consultant.aspx.vb" Inherits="consultant"%>
having moved the VB code into the .vb file and wrapped the code within that file in a Consultant class.

I am getting an error in the trimmed down .aspx file suggesting "'Context' is not a member of 'Consultant'" on the modified line above. Can anyone shed any light?
 
I would start by creating a NEW page that creates the code behind file for you. This way, all the code and events are "wired" up correctly.
 
ok I'll give that a try thanks. Is the creation of the code behind file automatic or do I have to change a specific setting or select a specific option?
 
Oh and excuse my ignorance, I'm from a classic ASP background where I place the script on an ISP-hosted web server and everything runs. Does this code behind / .NET approach require any compilation that could make hosting with an ISP tricky?
 
when you create a new page, there is a checkbox that states "place code in a separate file", make sure that is checked.

ASP.NET does require compilation. Based on what your ISP wants will determine if it is "tricky". However, I don't think it will be. Most people just deploy the compiled ddls.
 
Thanks again on both counts. I'll try out the new page tomorrow and check with our ISP.
 
Just an fyi, when you compile(Run) your code your codebehind files get compiled to assemblies (.dll) in your debug/release bin folders.



Ordinary Programmer
 
The "NEW" page approach seems to have worked, thank you. It gives rise to another problem but I think I'll start a new thread for that.

Have yet to hear from the ISP (this is a shared server).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top