code-behind & compilers

Results 1 to 2 of 2

Thread: code-behind & compilers

  1. #1
    Join Date
    Dec 1969

    Default code-behind & compilers

    i am using a windows 98 machine that is not able to run the compiler.<BR><BR>i want to use .vb files for code behind. specifically, i want to create a couple or more custom classes that i can call from multiple pages.<BR><BR>do .vb files need to be compiled in order for me to use them as code-behind?<BR><BR>can i put customized class definitions in .vb files? or do i have to put them in .dll files? (i know that .dll files need to be compiled) if i cannot put customized class definitions in .vb files, but yet if .vb files do not need to be compiled, i guess i can just write subroutines<BR><BR>whether i use subroutines or custom classes, i will want multiple pages to be able to call the same code-behind functionality, but i also want the flexibility of letting each of the various calling pages pass different parameters to the code block that i am using code-behind for. what do i need to add to my .ascx or .aspx files to 1.) hook up code-behind and 2.) pass unique parameters to the code block being called? please be careful to understand what i am asking: if i write a sub that takes 1 parameter and i store that sub in a code-behind file, do i merely need to reference the code-behind file at the top of the .ascx file and then place a line of code in the .ascx file&#039;s Page_Load sub calling the sub i want to run in the code-behind file? e.g. will know where to look if i call a sub from an .ascx file and the code for running the sub is located in the separate .vb code-behind file?<BR><BR>these are my questions. i make of a point of answering other people&#039;s questions when i have the answer. i would much appreciate it if some of you could sit down and rattle off answers to each of my questions. thanks in advance.

  2. #2
    Join Date
    Dec 1969

    Default RE: code-behind & compilers

    I read somewhere that if you use src= instead of codebehind= that you don&#039;t have to compile. I wouldn&#039;t put money on it though. <BR><BR>Yes you can put custom class definitions in a codebehind file. The entire codebehind file is a class file on its own that inherits the System.Web.UI.Page. All you would have to do is make your own class after the end of the definition of that class or even in a separate file and then declare that in your imports. Here is a class that I use:<BR><BR>Namespace samplenamespace<BR>Public Class NextUser<BR><BR>Private _User_CD As String<BR>Public Property User_CD() As String<BR>Get<BR>User_CD = _User_CD<BR>End Get<BR>Set(ByVal Value As String)<BR>_User_CD = Value<BR>End Set<BR>End Property<BR><BR>Private _User_Name_TXT As String<BR>Public Property User_Name_TXT() As String<BR>Get<BR>User_Name_TXT = _User_Name_TXT<BR>End Get<BR>Set(ByVal Value As String)<BR>_User_Name_TXT = Value<BR>End Set<BR>End Property<BR><BR>End Class<BR>End Namespace<BR><BR>I have it defined in a separate file with its own namespace definition around the entire file, and a bunch of class definitions similar to this one inside the namespace definition. Then in your codebehind file you would import projectname.namespace. <BR><BR>Once you are using codebehind you no longer need the script tags for server side script in the aspx page. There will be a Page_Load event in the codebehind page. You will then have access to object on the page when you define them inside your codebehind class file like this:<BR><BR>imports Project1.SampleNamespace<BR>Public Class Indexcontent<BR>Inherits System.Web.UI.Page <BR><BR>Protected WithEvents lblPageNumber As System.Web.UI.WebControls.Label<BR>Protected WithEvents txtSearchDate As System.Web.UI.WebControls.TextBox<BR><BR>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR><BR>end sub<BR>end class<BR><BR>I&#039;m not sure if I&#039;ve explained it very well, but there you have it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts