How to send variables to be used in a class?

S

Shapper

Hello,

How can I use a var1 and var2 in class ItemTemplate?
Basically, I need var1 and var2 which are declared on page load to be
avalaible in Class ItemTemplate when it's called.

Public Class webform

Inherits System.Web.UI.Page
...
Private Sub Page_Load(...) Handles MyBase.Load
...
Dim var1 As String = "A"
Dim var2 As String = "B"
column.ItemTemplate = CreateItemTemplate()
...
End Sub

Function CreateItemTemplate() As ITemplate
Return New ItemTemplate
End Function

End Class

Class ItemTemplate
...
End Class

Thanks,
Miguel
 
M

MattB

Shapper said:
Hello,

How can I use a var1 and var2 in class ItemTemplate?
Basically, I need var1 and var2 which are declared on page load to be
avalaible in Class ItemTemplate when it's called.

Public Class webform

Inherits System.Web.UI.Page
...
Private Sub Page_Load(...) Handles MyBase.Load
...
Dim var1 As String = "A"
Dim var2 As String = "B"
column.ItemTemplate = CreateItemTemplate()
...
End Sub

Function CreateItemTemplate() As ITemplate
Return New ItemTemplate
End Function

End Class

Class ItemTemplate
...
End Class

Thanks,
Miguel

Unless I'm not understanding you right, I think it may be as simple as this:

Public Class webform

Inherits System.Web.UI.Page
...
Private Sub Page_Load(...) Handles MyBase.Load
...
Dim var1 As String = "A"
Dim var2 As String = "B"
column.ItemTemplate = CreateItemTemplate(var1, var2)
...
End Sub

Function CreateItemTemplate(ByVal var1 as String, ByVal var2 as
string) As ITemplate
Return New ItemTemplate
End Function

End Class

Class ItemTemplate
...
End Class
------------

Keep in mind the local names inside CreateItemTemplate are arbitrary and
don't need to match the ones being passed in (var1 and var2).

HTH,

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top