473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Economize code

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
Jan 7 '07 #1
4 1153
Yup, sure. It's best if you modify the SetLink to accept the control as a
parameter
SetLink(Dim c As Control). That entire block of code can then be placed in a
module or global file so that it is callable from every page.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc

"Morten Snedker" <fi**@alotofsites.comwrote in message
news:gs********************************@4ax.com...
>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

Jan 8 '07 #2
On Sun, 7 Jan 2007 22:20:34 -0500, "Alvin Bruney [MVP]" <some guy
without an email addresswrote:

Don't know if there an English/US equalivant: sometimes you can't see
the forrest for the trees. :-)

Thanks for your input.

Regards /Snedker
>Yup, sure. It's best if you modify the SetLink to accept the control as a
parameter
SetLink(Dim c As Control). That entire block of code can then be placed in a
module or global file so that it is callable from every page.
Jan 8 '07 #3
On Sun, 7 Jan 2007 22:20:34 -0500, "Alvin Bruney [MVP]" <some guy
without an email addresswrote:
>Yup, sure. It's best if you modify the SetLink to accept the control as a
parameter
SetLink(Dim c As Control). That entire block of code can then be placed in a
module or global file so that it is callable from every page.
I can't figure out where to put the procedure so that it is runnable
from all pages.

E.g. the code

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

FindControl is not "usable" if put in a module of its own. I can't
figure out how to make this code global for use on alle pages (ascx).

Regards /Snedker
Jan 8 '07 #4
Put it in the global asax.cs. That is callable from anywhere.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc

"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:hi********************************@4ax.com...
On Sun, 7 Jan 2007 22:20:34 -0500, "Alvin Bruney [MVP]" <some guy
without an email addresswrote:
>>Yup, sure. It's best if you modify the SetLink to accept the control as a
parameter
SetLink(Dim c As Control). That entire block of code can then be placed in
a
module or global file so that it is callable from every page.

I can't figure out where to put the procedure so that it is runnable
from all pages.

E.g. the code

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

FindControl is not "usable" if put in a module of its own. I can't
figure out how to make this code global for use on alle pages (ascx).

Regards /Snedker

Jan 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.