473,320 Members | 1,953 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,320 software developers and data experts.

Public click event for a hyperlink

17
Hi,

I am lost when it comes to creating a click event in asp.

I have hyperlinks that are pulled dynamically from a table. An example is Hockey is a hyperlink.

What I want to do is when a user selects the Hockey link, information regarding Hockey will be pulled from another table and displayed on a page.

In order to do this, I have to create the click event for when the user selects the hyperlink Hockey it will pull the info from the Subprograms table.

My problem is I don't know how to refer to the click event with the hyperlink.

Here is my code that created the hyperlinks.
Expand|Select|Wrap|Line Numbers
  1.  <%
  2.      Dim conn, rs, query
  3.   if request.querystring("display") = "Programs" then
  4. 'Create an ADODB connection
  5.  Set conn = Server.CreateObject("ADODB.Connection")
  6.  
  7. 'Open the database
  8.  conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentre;UID=myUserID;PWD=myPWD;"
  9.  
  10. 'Execute the SQL and assign to our Recordset
  11. set rs = Server.createobject("ADODB.recordset")
  12. query = "SELECT description FROM programtbl"
  13.  
  14. LinkChosen=Programs">Programs</a>
  15.  
  16. rs.Open query, conn%>
  17. <%response.write "<br>"& vbNewLine 
  18.  
  19.  
  20. do until rs.eof %>
  21.  
  22. <a href="ValourCC.asp?program=<%=rs("description")%>"><%=rs("description")%></a> 
  23.  
  24.  
  25.  
  26. <%
  27.  
  28.     rs.MoveNext
  29.    loop
  30. end if
  31.  %>
  32.  
  33. </div>
Public Program click_event ?????
Sep 25 '07 #1
6 2382
jhardman
3,406 Expert 2GB
Mona,

I've removed your password and user name from your code. Please notice that this is a public forum and posting you user name and password is a potentially serious security risk.

The thing is, I'm not sure you want to create a click event (whatever that means to you). It looks to me like you want to link to a second page (called "valourCC.asp?program=hockey") when you click the link. On this second page you can now open the database with something like this:
Expand|Select|Wrap|Line Numbers
  1. query = "SELECT * FROM myTable WHERE description = '"
  2. query = query & request.querystring("program") & "'"
  3.  
  4. rs.open query, conn
Does this make sense?

Jared
Sep 25 '07 #2
mramsay
17
Thanks,

I'll try it out and let you know.

Mona
Sep 26 '07 #3
mramsay
17
Hi,

So far I have a Programs hyperlink that is working by pulling the info from the programs table which is Sports, Youth Programming, etc.

Now I have to get the code to work when the Sports link is selected I would like to pull the information from the Subprogramstbl. There is a heading in the subprogramstbl called Sports.

Under this heading there are fields of sports such as baseball and hockey.

When I select the Sports link nothing happens. Baseball and Hockey are not displayed.

This is what I have.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.      Dim conn, rs, query
  3.   if request.querystring("display") = "Programs" then
  4. 'Create an ADODB connection
  5.  Set conn = Server.CreateObject("ADODB.Connection")
  6.  
  7. 'Open the database
  8.  conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=?????;Database=communitycentre;UID=???;PWD=???;"
  9.  
  10. 'Execute the SQL and assign to our Recordset
  11. set rs = Server.createobject("ADODB.recordset")
  12. query = "SELECT description FROM programtbl"
  13.  
  14.  ' Dim selected, query
  15. ' get the item that was passed in the querystring.
  16. ' selected = Request.QueryString("LinkChosen")
  17.  
  18.  
  19. '   <a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs">Programs</a>
  20.  
  21. rs.Open query, conn%>
  22. <% response.write "<br>"& vbNewLine 
  23.  
  24.  
  25. do until rs.eof %>
  26.  
  27. <a href="ValourCC.asp?program=<%=rs("description")%>"><%=rs("description")%></a> 
  28.  
  29.  
  30.  
  31. <%
  32.  
  33.     rs.MoveNext
  34.    loop
  35. end if
  36.  %>
  37.  
  38. </div>
  39.  
  40.  
  41. <% 
  42. if request.querystring("display") = "Sports" then
  43.  
  44. 'Create an ADODB connection
  45.  Set conn = Server.CreateObject("ADODB.Connection")
  46.  
  47. 'Open the database
  48.  conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=???;Database=communitycentre;UID=????;PWD=???;"
  49.  
  50. 'Execute the SQL and assign to our Recordset
  51. set rs = Server.createobject("ADODB.recordset")
  52. query = "SELECT Sports from Subprogramstbl"
  53. query = query & request.QueryString ("sports") & "'"
  54.  
  55. rs.Open query, conn%>
  56. <% response.write "<br>"& vbNewLine%> 
  57.  
  58.  
  59. <%do until rs.eof%> 
  60.  <a href="ValourCC.asp?program=<%=rs("sports")%>"><%=rs("sports")%></a> 
  61.  
  62. <%
  63.  
  64.     rs.MoveNext
  65.    loop
  66. end if
  67.  %>
Thanks for all your help. I think I would rip my hair out if I didn't have your help.
Sep 28 '07 #4
jhardman
3,406 Expert 2GB
You are on the right track. I think one of the things that is confusing you is that to connect with a database you need to use a different language altogether from the ASP (vbscript) language. This other "language" is "SQL" and it is just a standard way to send a request to a database, and any db should be able to understand the request and give you the results. The lines where you say "query = ..." you are making a SQL query. The basic syntax is:
Expand|Select|Wrap|Line Numbers
  1. SELECT fieldName1, fieldName2 FROM myDatabaseTable WHERE fieldName3 = 'happy'
This will pull up two fields (fieldName1, fieldName2) from every record where fieldName3 = "happy". Does this make sense? Notice that SQL is almost readable English. Your lines 52 and 53 make this SQL query which is obviously in bad syntax:
Expand|Select|Wrap|Line Numbers
  1. SELECT Sports from Subprogramstblfootball'
We make this kind of mistake all the time. Experienced programmers like to print out this line so we can read it. The code for printing it out would be:
Expand|Select|Wrap|Line Numbers
  1. response.write "<br>" & query & "<br>" & vbNewLine
Looking at the above SQL query, you should recognize that there is something wrong, even if you are not sure what the correct query should be. Do you agree? The correct query should look something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT Sports FROM Subprogramstbl WHERE fieldName1 = 'football'
Notice that this will make the db give you the field "Sports" from every record where fieldName1 = 'football'. I'm not sure this is what you want. It is likely that you want every field from the records where the field "Sports" equals 'football'. If this is the case, the query should look like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Subprogramstbl WHERE Sports = 'football'
Does this syntax make sense? To make the ASP code form this query, I would write it like this:
Expand|Select|Wrap|Line Numbers
  1. query = "SELECT * FROM Subprogramstbl WHERE Sports = '"
  2. query = query & request.QueryString ("sports") & "'"
Look through this and make sure everything I said makes sense. Try it out and see what you get.

Jared
Sep 28 '07 #5
mramsay
17
Hi,

I understand what you are saying for the sql code.

I want all the fields under the heading sports to be displayed as links. Same as how I displayed the hyperlinks under Programs.

So now when the user selects the programs hyperlink, sports, youth programming links are displayed.

Now when the user selects sports hyperlink they want to see what sports are offered. I've went over my code, and everything looks fine except when I click on the sports hyperlink. The fields under Sports are not displaying.

I thought it was because my response.write code was not working properly, but it looks fine.

I've attached the code again, to see if you can see what the problem is.

<%
Dim conn, rs, query
if request.querystring("display") = "Programs" then
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=????PWD=???;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT description FROM programtbl"

' Dim selected, query
' get the item that was passed in the querystring.
' selected = Request.QueryString("LinkChosen")


' <a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs">Programs</a>

rs.Open query, conn%>
<% response.write "<br>"& vbNewLine


do until rs.eof %>

<a href="ValourCC.asp?program=<%=rs("description")%>" ><%=rs("description")%></a>



<%

rs.MoveNext
loop
end if
%>




<%
if request.querystring("display") = "Sports" then

'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=???;PWD=???;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT Sports from Subprogramstbl"
query = query & request.QueryString ("sports") & " ' "


rs.Open query, conn
response.write "<br>" & query & "<br>" & vbNewLine


do until rs.eof%>
<a href="ValourCC.asp?sports=<%=rs("sports")%>"><%=rs ("sports")%></a>

<%

rs.MoveNext
loop
end if
%>
Oct 1 '07 #6
mramsay
17
Hi,

I understand what you are saying for the sql code.

I want all the fields under the heading sports to be displayed as links. Same as how I displayed the hyperlinks under Programs.

So now when the user selects the programs hyperlink, sports, youth programming links are displayed.

Now when the user selects sports hyperlink they want to see what sports are offered. I've went over my code, and everything looks fine except when I click on the sports hyperlink. The fields under Sports are not displaying.

I thought it was because my response.write code was not working properly, but it looks fine.

I've attached the code again, to see if you can see what the problem is.

<%
Dim conn, rs, query
if request.querystring("display") = "Programs" then
'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=????PWD=???;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT description FROM programtbl"

' Dim selected, query
' get the item that was passed in the querystring.
' selected = Request.QueryString("LinkChosen")


' <a href="http://localhost/ValourCommunityCentre/ValourCC.asp?LinkChosen=Programs">Programs</a>

rs.Open query, conn%>
<% response.write "<br>"& vbNewLine


do until rs.eof %>

<a href="ValourCC.asp?program=<%=rs("description")%>" ><%=rs("description")%></a>



<%

rs.MoveNext
loop
end if
%>




<%
if request.querystring("display") = "Sports" then

'Create an ADODB connection
Set conn = Server.CreateObject("ADODB.Connection")

'Open the database
conn.Open "Driver={MySQL ODBC 3.51 Driver};Server=24.79.93.78;Database=communitycentr e;UID=???;PWD=???;"

'Execute the SQL and assign to our Recordset
set rs = Server.createobject("ADODB.recordset")
query = "SELECT Sports from Subprogramstbl"
query = query & request.QueryString ("sports") & " ' "


rs.Open query, conn
response.write "<br>" & query & "<br>" & vbNewLine


do until rs.eof%>
<a href="ValourCC.asp?sports=<%=rs("sports")%>"><%=rs ("sports")%></a>

<%

rs.MoveNext
loop
end if
%>

--------------------------------------------------------------------------------
Oct 2 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Pat | last post by:
How do I trigger the click event of the hyperlink control programmatically? Thanks
4
by: | last post by:
Does anyone know how to trigger the click event of a hyperlink control programmatically? Thanks for helping.
2
by: Doug Stiers | last post by:
I have an asp:hyperlink that I need to have some code fire when the link is clicked. The link is in a datagrid and the link is working properly. I tried using the OnInit event to call the...
3
by: | last post by:
Hi I am using vb.net code behind. In my code I have a button click event on my main web form. Private Sub btNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
0
by: Allan Ebdrup | last post by:
Why doesn't the Hyperlink Control have a serverside click event? I would like to run some serverside code when a user clicks on a link, do I really have to insert a button and format it as a...
2
by: samuelberthelot | last post by:
Hi, Hi have a hyperlink column in my datagridview. How can I capture the click event on the hyperlink ? Thank you
3
by: smHaig | last post by:
Not being an web programmer I am unable to figure out how to put the hyperlink mailto:emailaddress in a button click event. I do not want a hyperlink on the form. I have found nothing to address...
2
by: nani | last post by:
Hi friends I am creating one web application in that i take one hyperlink control.when i click hyperlink control.how to split the page in two parts and display the result in that secound part If...
4
by: SAL | last post by:
Hello, I'm working, basically my first, AJAX page and am having a few problems. One is that the Click event for a button I have in UpdatePanel1 is not getting called. I've tried with the button...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.