0

I have two aspx pages the first page has a textbox and the second aspx page has one textbox

In the second Page I am giving value to the text box by generating a session and giving that session ID to the textbox on the samepage

Now I need to retrieve back that session ID from the textbox and display it in first aspx page textbox which is not happening and not getting any error.

Here is my code for the first aspx page:

<asp:TextBox ID="CopySession" runat="server"></asp:TextBox>

This is my code for displaying the retrieved Session ID:

 If  IsPostBack Then
            Dim text1 As TextBox = Me.PreviousPage.FindControl("SessionValue")
            CopySession.Text = text1.Text
 End If

This is my second aspx page:

<asp:TextBox ID="SessionValue" runat="server"></asp:TextBox>

This is my code behind for second aspx page:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Session("ID") Is Nothing Then
              Session("ID") = Guid.NewGuid.ToString
              SessionValue.Text = Session("ID")
            End If
End Sub
coder
  • 13,002
  • 31
  • 112
  • 214

3 Answers3

2

Its quite simple just type cast it with previous page like following

(Me.PreviousPage as yourPageClass).SessionValue.Text

or use this on first page

<%@ PreviousPageType VirtualPath="~/SecondPage.aspx" %>

and better way is

 internal function TextBoxText() as string
       return SessionValue.Text
 end function

and get it on page one

currentPageTextbox.Text = Page.PrevousPage.TextBoxText
  • I dont get by "yourPageClass" what do I mention instead of that as I don't have any Class. – coder Oct 16 '11 at 18:30
1

Am also looking around the same scenario and I found this URL as useful to me.

Am sharing this to you.. Exploring Session in ASP.Net

Refer this too

How can I access Session vars from Base class in ASP.Net?

ASP.Net MVC: How do you access the session from a different project within the solution?

Community
  • 1
  • 1
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • Thanks for your reply I have gone through it before but it's working for some and In the case above I don't know what's happening it's just showing me blank value. – coder Oct 16 '11 at 18:30
1

If you put it Session, just retrieve it. On Page_Load of your first page, do:

Dim sessionID As String = TryCast(Session("ID"), String)
If Not String.IsNullOrEmpty(sessionID) Then
    SessionValue.Text = sessionID
End If
Icarus
  • 63,293
  • 14
  • 100
  • 115