[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set session variable asp.net vb onclick of hyperlink

Posted on 2009-05-01
3
Medium Priority
?
1,683 Views
Last Modified: 2012-08-14
For various reasons I need  to set a session variable when clicking a hyperlink.  I know this is basic but I can't figure out what I'm doing wrong.

My code is below.  Any help if much appreciated.

Thanks,
Christopher
My Function: 
<script language="VB" runat="server">
Sub setEventId(Source As Object, E As EventArgs)
    Session("eventId") = sp_EventDetail.FieldValue("eventId")
End Sub
</script>
  
My Link: 
<asp:HyperLink id="link1" NavigateUrl="test2.aspx" target='_self' OnClick="setEventId" runat="Server">Test</asp:HyperLink></ContentsTemplate>

Open in new window

0
Comment
Question by:cbruno33
3 Comments
 
LVL 17

Expert Comment

by:OriNetworks
ID: 24284711
What is sp_EventDetail?
Could you post all code?

Also, keep in mind that when you click that link, the page does a postback meaning that the page is reloaded, the page_load event is run and then your sub setEventId runs.
0
 

Author Comment

by:cbruno33
ID: 24284887
Hi and thanks for the reply.  

Attached is code for the entire page and here is a link to the page (sorry it's a bit of a mess).

Here's what I'm trying to do and maybe there's a better approach.  
The sp_EventDetail is a dataset (return by a stored procedure) that contains a list of calendar events.  These events are displayed in a table.  My "test" link is included with every row.  When clicked I want to set a session variable named eventId to the eventId of the row with the hyperlink.

The reason I'm not passing this in the URL is because of a strange situation.  The link will actually go to an .html page.  From the html page, the user will navigate to an aspx page.  When they get to that 2nd html page, I need access to the eventId associated with the calendar event they clicked two pages back.  I thought I could do this using a session variable.  Is there some other way?

Thanks again.  
test.txt
0
 
LVL 6

Accepted Solution

by:
M3mph15 earned 500 total points
ID: 24292173
Hi,

Try using a LinkButton instead of a Hyperlink. They will look exactly the same and you will be able to use the OnClick event of the LinkButton so you can add the Session variable.

HTH
-M3mph15
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question