Writing a html string from a sub in a user control file

C

Christian Perthen

Hi,

I have a sub in the codebehind page of a user control file that writes html.
How do I get the sub triggered and output the html in the content page?
See my approach below.


Partial Class contentAffiliate
Inherits System.Web.UI.UserControl

Sub Page_Load()
writeContentAffiliateSub(1, 1)
End Sub

Sub writeContentAffiliateSub(ByVal intDisplayMode As Integer, ByVal
intPageID As Integer)
Response.Write("<table cellpadding=""0"" cellspacing=""0""><tr>")
Response.Write("<td nowrap " & writeActiveTab(intPageID, 1) & "><a
href=""affiliate_list.aspx"">Active Affiliates</a></td>")
Response.Write("<td nowrap " & writeActiveTab(intPageID, 2) & "><a
href=""affiliate_list.aspx?active=1"">Temporary Affiliates</a></td>")
Response.Write("<td nowrap " & writeActiveTab(intPageID, 3) & "><a
href=""affiliate_list.aspx?active=0"">Inactive Affiliates</a></td>")
Response.Write("<td nowrap " & writeActiveTab(intPageID, 4) & "><a
href=""affiliate_new.asp"">New Affiliate</a></td>")
Response.Write("<td nowrap " & writeActiveTab(intPageID, 5) & "><a
href=""affiliate_usage.asp"">Affiliate Usage</a></td>")
Response.Write("</tr></table>")
End Sub

Function writeActiveTab(ByVal intPageID As Integer, ByVal intTabID As
Integer) As String
If intPageID = intTabID Then
writeActiveTab = "class=""active"""
Else
writeActiveTab = "class=""inactive"""
End If
End Function

End Class



in the content page I have:

<%@ Register TagPrefix="tab" TagName="contentAffiliate"
Src="~\controls\contentAffiliate.ascx" %>

<tab:contentAffiliate id="contentAffiliate"
runat="server"/></tab:contentAffiliate>

But nothing is generated

Any insight on this?

Thanks in advance
Christian
 
K

Kris

Hi Christian,

Add Table tag in .ascx page as a server HTML tag, and add the rows and
columns to the table from code behind file.

<table id="tblDisplay" runat="server"></table>

Dim dRow as New HtmlTableRow
Dim dColumn as New HtmlTableColumn

dColumn.Text = "test"
dRow.Columns.add(dColumn)
tblDisplay.Rows.Add(dRow)

Hope this would help you.

Cheers,
Kris
 

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