cbruno33
asked on
Set session variable asp.net vb onclick of hyperlink
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 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>
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.