Class question

A

Anonymous

Hey,

in my init I created some code to create a tabbed
interface. The code worked very well. It simply adds a
table with the required cells/rows to a placeholder, which
is located on the page. Now I tried to implement this in a
seperate class. I created a new namespace which has a
class in it. The class contains a public function, which
is exactly the same code as I had before in init. The
function retuns me a placeholder. From my original webform
then again, I am calling that function and assigning the
return value to the placeholder. However I dont see the
tabed interface? Any idea what it could be? Here is my
code:


Imports Microsoft.ApplicationBlocks.Data
Imports System.Data.SqlClient
Imports System.Data

Namespace intranet
Public Class Menu
Inherits System.Web.UI.Page

Public Function CreateTopTabbedMenu() As
PlaceHolder

....

Dim iLoop As Integer = 0
Dim table As New Table
table.BackColor =
System.Drawing.Color.Gainsboro
table.CellPadding = 2
table.CellSpacing = 0

Dim tr As New TableRow

For iLoop = 0 To dsHeaderLinks.Tables(0).Rows
().Count() - 1
Dim td As New TableCell
td.ID = dsHeaderLinks.Tables(0).Rows(iLoop)
("ID")

If iLoop = 0 Then
td.Attributes.Add
("class", "SelectedCell")
Else
td.Attributes.Add
("class", "UnSelectedCell")
End If

Dim link As New HyperLink
link.Font.Bold = True
link.Text = "  " &
dsHeaderLinks.Tables(0).Rows(iLoop)("LinkText")
& "  "
link.NavigateUrl = "/intranet" &
dsHeaderLinks.Tables(0).Rows(iLoop)("Link") & "?Index=" &
dsHeaderLinks.Tables(0).Rows(iLoop)("ID")
link.ToolTip = IIf(IsDBNull
(dsHeaderLinks.Tables(0).Rows(iLoop)("LinkTooltip")), "",
dsHeaderLinks.Tables(0).Rows(iLoop)("LinkTooltip"))

td.Controls.Add(link)
tr.Cells.Add(td)
Next

table.Controls.Add(tr)
Dim HeaderMenuHolder As New PlaceHolder
HeaderMenuHolder.Controls.Add(table)

Return HeaderMenuHolder
End Function

End Class
End Namespace

And here is how I am calling to from the webform in init:

Dim objMenu As New intranet.Menu
HeaderMenuHolder = objMenu.CreateTopTabbedMenu()

Thanks
 
K

Kevin Spencer

You were correct to want to create a class (good OOP), but you should create
a custom Server Control instead of what you're trying to do. What you've
described as your requirement is an exact description of a Server Control.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
A

Anonymous

Addtional information:

I also need to create child controls based on the
selection of the header menu. I would like to do this all
in a class. Do you still recommend to create a custom
server control? I never created one.

Thanks Kevin
 
K

Kevin Spencer

I still do recommend it, Anonymous. If you've never created a Server
Control, you might want to take a look at a series of introductory articles
I wrote on the subject on my web site: http://www.takempis.com. Also, the
..Net SDK has invaluable articles on the subject.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

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