Link to home
Start Free TrialLog in
Avatar of erockman9

asked on

Transfer a session in an hyperlink in detailsview with apsx

i've got a gridview that passes a session to a detailview(1), which works great.  Then i want to link back to the detailview(1) from another detailview(2) using a hyperlink.  how do i get the hyperlink to pass a session instead of a querystring so detailview1 will capture it.

i'm using VS 2008 with VB language.
Avatar of samtran0331
Flag of United States of America image

A session variable is available as long as the session is once you set a session, it is there, you don't need to "pass it" like a querystring variable....are you asking how to set it?
Avatar of erockman9


Note: the pages pull from seperate Databases and are linked
actually it works fine as long as i go from page 1 to page 2 (the detail page) first.  in other words if i populate page2  it sets the session and then when i go to page 3 and hyperlink back to page 2 it looks awesome...the problem is sometimes i want to start in page3 and go back to page 2...i have either the wrong sessionvariable or no session variable in place.  maybe what i'm trying to do is reset and set a new session variable at that that possible?

From what I understand..the detailview on page 3 has a hyperlink that goes back to page 2
And if the user didn't go from page 2 to page 3 and back to page 2, you have problems (because they started on page 3 and you set the session on page 2).

If you don't want to use querystring variables....I would suggest instead of using a hyperlink to go from page 3 to page 2, if you use a linkbutton, then in codebehind, you can make sure the session variable in question is set correctly and then response.redirect back to page 2...
i tried that which makes the most sense.

the only problem im having is adding a linkbutton and then getting to the code behind within the detailview.  
can you post the code you have?
the code behind is first then the source code.
all i really need is a way to attach the session variable to a button in the detailsview...
i keep think i'm missing something obvious.

Public Partial Class Eligibility_AccountDetail
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand
        Session("CarrierId") = DetailsView1.SelectedValue
    End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="Eligibility_AccountDetail.aspx.vb" Inherits="WebApplication16.Eligibility_AccountDetail" 
    title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
            width: 100%;
            width: 122px;
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <table cellpadding="0" class="style8">
            <td class="style9">
                <asp:DetailsView ID="DetailsView1" runat="server" 
                    AutoGenerateRows="False" DataKeyNames="AccountId" DataSourceID="SqlDataSource1" 
                    Height="50px" Width="355px">
                        <asp:BoundField DataField="AccountId" HeaderText="AccountId" ReadOnly="True" 
                            SortExpression="AccountId" />
                        <asp:BoundField DataField="AccountName" HeaderText="AccountName" 
                            SortExpression="AccountName" />
                        <asp:BoundField DataField="CarrierId" HeaderText="CarrierId" 
                            SortExpression="CarrierId" />
                        <asp:BoundField DataField="FromDate" HeaderText="FromDate" 
                            SortExpression="FromDate" />
                        <asp:BoundField DataField="ThruDate" HeaderText="ThruDate" 
                            SortExpression="ThruDate" />
                        <asp:BoundField DataField="Address1" HeaderText="Address1" 
                            SortExpression="Address1" />
                        <asp:BoundField DataField="Address2" HeaderText="Address2" 
                            SortExpression="Address2" />
                        <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                        <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
                        <asp:BoundField DataField="ZipCode" HeaderText="ZipCode" 
                            SortExpression="ZipCode" />
                        <asp:BoundField DataField="ZipCode2" HeaderText="ZipCode2" 
                            SortExpression="ZipCode2" />
                        <asp:BoundField DataField="Contact" HeaderText="Contact" 
                            SortExpression="Contact" />
                        <asp:BoundField DataField="ContactEmail" HeaderText="ContactEmail" 
                            SortExpression="ContactEmail" />
                        <asp:ButtonField Text="Button" />
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:rxclaimsConnectionString %>" 
                    SelectCommand="SELECT * FROM [Account] WHERE ([AccountId] = @AccountId) ORDER BY [AccountId]">
                        <asp:SessionParameter Name="AccountId" SessionField="AccountID" Type="String" />
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">

Open in new window

Avatar of samtran0331
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
awesome...i will use that technique on many many pages!!!!