M
Morten Snedker
I have three web-controls (ascx) on my page, all containing graphics
with a hyperlink. The information for these hyperlinks are stored in a
database.
On the Page_Load of each web-control I run the code below.
What I can't figure out is if I can make it global, so that on each
Page_Load I call the SetLinks procedure. Is this possible, given the
content of SetLinks?
Or should I consider a whole new approach?
Sub SetLinks()
Dim h As HyperLink
Dim c As Control
Dim da As New DataAccess
Dim reader As SqlDataReader = da.AdList
Try
If reader.HasRows Then
While reader.Read
c = FindControl(reader(1).ToString)
If Not c Is Nothing Then
h = CType(c, HyperLink)
h.NavigateUrl = reader(2).ToString
h.Text = reader(3).ToString
h.Target = reader(4).ToString
End If
End While
End If
Catch ex As Exception
Response.Write(ex.Message)
'don't throw exception to user
'this should be handled through admin-part
Finally
reader.Close()
da.Close()
End Try
End Sub
Regards /Morten
with a hyperlink. The information for these hyperlinks are stored in a
database.
On the Page_Load of each web-control I run the code below.
What I can't figure out is if I can make it global, so that on each
Page_Load I call the SetLinks procedure. Is this possible, given the
content of SetLinks?
Or should I consider a whole new approach?
Sub SetLinks()
Dim h As HyperLink
Dim c As Control
Dim da As New DataAccess
Dim reader As SqlDataReader = da.AdList
Try
If reader.HasRows Then
While reader.Read
c = FindControl(reader(1).ToString)
If Not c Is Nothing Then
h = CType(c, HyperLink)
h.NavigateUrl = reader(2).ToString
h.Text = reader(3).ToString
h.Target = reader(4).ToString
End If
End While
End If
Catch ex As Exception
Response.Write(ex.Message)
'don't throw exception to user
'this should be handled through admin-part
Finally
reader.Close()
da.Close()
End Try
End Sub
Regards /Morten