Adding Code Behind File to a project

praveensg

Newcomer
Joined
Jan 23, 2004
Messages
23
Hello Friends,
I am very new to .Net and the VS.Net IDE. So I will definitely sound silly to you guys when I ask this question. I have been working on an ASP.Net project from quite some time now. However, most of the coding I did using Dreamweaver (No VS.Net IDE). I have a code behind file that I use to set up a connection with the SQL Server Database. And I use the classes within this file in aspx pages where I need to setup a connection. I used a code behind file so that I could change the connection string easily every time I uploaded my files to the production server.

Now, I am trying to make use of a readymade web control in one of my aspx pages. For that, I tried using VS.Net IDE. However, it throws me an error saying that the class I'm using within an aspx page is not available. Now I know that code behind file contains the class. However, I do not know how to add this code behind file to my project/solution.

Please elaborate with a solution for my problem.

Also please let me know what is a solution, project. And how do I change the default directory that is used to create solutions.

Thanx a lot,
Praveen
 
have you added a reference to your third party assembly in your project/page???

there should be an entry at the top of your .aspx like:

PHP:
<%@ Register TagPrefix="[third party tagprefix here]"  Namespace="[third party namespace here]" Assembly="[third party assembly name here]" %>
 
 
if using a web project, be sure to add the assembly to the references section using solution explorer
 
Joe Mamma said:
have you added a reference to your third party assembly in your project/page???

there should be an entry at the top of your .aspx like:

PHP:
<%@ Register TagPrefix="[third party tagprefix here]"  Namespace="[third party namespace here]" Assembly="[third party assembly name here]" %>
 
 
if using a web project, be sure to add the assembly to the references section using solution explorer[/QUOTE]

Thanq for the reply Joe.
However, my problem is I'm not able to add a codebehind (.vb) file to my project.

I have something like

[CODE]<%@ Page Inherits = "MyCodeBehind" CodeBehind="SimpleCodeBehind.vb" Language="VB" Explicit="True" %>[/CODE] 

But it says it cannot find class MyCodeBehind in SimpleCodeBehind.vb. And SimpleCodeBehind.vb does not show up in the Solution Explorer:(
 
praveensg said:
Thanq for the reply Joe.
However, my problem is I'm not able to add a codebehind (.vb) file to my project.

I have something like

Code:
<%@ Page Inherits = "MyCodeBehind" CodeBehind="SimpleCodeBehind.vb" Language="VB" Explicit="True" %>

But it says it cannot find class MyCodeBehind in SimpleCodeBehind.vb. And SimpleCodeBehind.vb does not show up in the Solution Explorer:(
Ok, whats not being seen?
a) 'ready made' web control (compiled dll assembly)?
b) third party VB source file with a class definition?
c) class module you have written?

The latter two require adding the file to the project
the first requires adding a reference to the assembly

in the case of
<%@ Page Inherits = "MyCodeBehind" CodeBehind="SimpleCodeBehind.vb" Language="VB" Explicit="True" %>

this says 'The current .aspx page inherits from the class "MyCodeBehind" (which must inherit from System.Web.UI.Page) which is defined in "SimpleCodeBehind.vb"

from what you are saying, you want to use someone elses control on your page. Is that correct?
 
Joe Mamma said:
Ok, whats not being seen?
a) 'ready made' web control (compiled dll assembly)?
b) third party VB source file with a class definition?
c) class module you have written?

The latter two require adding the file to the project
the first requires adding a reference to the assembly

in the case of
<%@ Page Inherits = "MyCodeBehind" CodeBehind="SimpleCodeBehind.vb" Language="VB" Explicit="True" %>

this says 'The current .aspx page inherits from the class "MyCodeBehind" (which must inherit from System.Web.UI.Page) which is defined in "SimpleCodeBehind.vb"

from what you are saying, you want to use someone elses control on your page. Is that correct?

Yes my case is c) I have already written the class module which I want to make use of in my prj. I added the .vb file to the project by adding it as a new item with the help of the solution explorer. however, it does not show up in the solution explorer. And I think this is the reason it throws me the error that it cannot find the inherited class:(
 
praveensg said:
Yes my case is c) I have already written the class module which I want to make use of in my prj. I added the .vb file to the project by adding it as a new item with the help of the solution explorer. however, it does not show up in the solution explorer. And I think this is the reason it throws me the error that it cannot find the inherited class:(
is 'MyCodeBehind' derived from System.Web.UI.Page ?
 
Joe Mamma said:
is 'MyCodeBehind' derived from System.Web.UI.Page ?

Hi Joe,
Yes I think it is derived from System.Web.UI.Page!!!
This is my codebehind code. Now I try to add this in my project, and it doesn't show up in the Sol Explorer:(

Code:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.Page

Public Class MyCodeBehind : Inherits Page
Public strOutput as String
Public strConnection As String

Public Sub SetstrConn
strConnection="data source=QMWORKS;User ID=praveen;Password=********;database=crustali;Connect Timeout=30;"
End Sub

Public Sub btnCancel_Click(Sender as Object, E as EventArgs)
Response.Redirect("Homepage.aspx")
End Sub

Public Sub LogOutClick(sender as System.Object, e As System.EventArgs)
Session.Abandon()
Response.Redirect("Login.aspx")
End Sub


Public Structure Product_Info
    Dim Name As String 
    Dim Unit As String 
    Dim Species As Integer
End Structure

Public Structure CruiseDataSet
    Dim DataSetName As String 
    Dim TractStandName As String 
    Dim TallyType As String
    Dim CruiseType As String
    Dim PlotBAFSize As Single
    Dim NumberOfPlots As Integer
    Dim AcresInTally As Single
    Dim ProductInfo() As Product_Info 
End Structure
 
Public Structure DataSetProdSpec
 Dim SpeciesName As String 
 Dim MinDBH As Single
 Dim MaxDBH As Single
 Dim DBHInt As Integer
 Dim HtMeasure As String
 Dim LogLen As Single
 Dim MinHt As Single
 Dim MaxHt As Single
 Dim HtInt As Single
 Dim VolEq As Integer
 Dim FrmCls As Integer
 Dim LRule As String
 Dim TblName As String 
 Dim No(,) As Integer
End Structure

End Class
 
Last edited:
Back
Top