Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Classes and Codebehind pages

  Asked By: Bonni    Date: Aug 21    Category: Asp.net    Views: 663
  

Suppose I´m coding with notepad(no fancy VS.NET shortcuts). Now, in
directory foo I have 3 pages :pg1.aspx, pg1.apsx.vb (codebehind file),
class1.vb. How can I use class1 methods/values inside pg1.apsx.vb ?
Relevante code is below.

- pg1.aspx :


<%@src="pg1.aspx.vb" Inherits="pg1"%>
<html>
<asp:Label id="Label1" runat="server">l1</asp:Label>
</html>


- pg1.apsx.vb

Public Class pg1
Inherits System.Web.UI.Page

Protected WithEvents Label1 As System.Web.UI.WebControls.Label

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim c As Class1
c = New Class1("1")

Label1.Text = c.strValue
End Sub

End Class

- class1.vb

Public Class Class1

Public strValue As integer

Public Sub New(ByVal Value As Integer)
strValue = Value * 2
End Sub

End Class

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Feodora Bonkob     Answered On: Aug 21


If you already have class1 compiled and the .dll copied to the application's
bin directory -- you can just reference the namespace at the top of your
code-behind source (with the "Imports" statement in VB, and "using" in C#)
and create an instance of your class...

 
Didn't find what you were looking for? Find more on Classes and Codebehind pages Or get search suggestion and latest updates.




Tagged: