Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

There is one problem regarding Page Redirection. Here is Sample code
1) Database Connection -> Done
2) Insert Data -> Done
3) Add value inside Session variable -> Done
4) Redirect to success page -> Problem come up Here :(

Default1.aspx:
VB
......
Dim success As String = "Success"
......
'btn_Click Event
    Try
        sqlCom.ExecuteNonQuery()
        sqlCon.Close()
        Session("success") = success
        MsgBox(Session("success") 'Msg Prints Properly

        modifyXmlData(filePath); ' Modifies the attribute value
        '1st Approach
        Response.Redirect("default2.aspx", False)
        '2st Approach
        'Server.Execute("default2.aspx", False)
        Catch ex As Exception
        MsgBox("Exception" + ex.Message)
        'lbl_Success.Text = ex.Message
    End Try
End Sub

Protected Sub modifyXmlData(ByVal filepath As String)
        Dim strPath = Server.MapPath(filepath)
        Dim xmlFile = XDocument.Load(strPath)

        xmlFile.<root>.<ListItem>.Where(Function(f) _
                        f.@value = ddl_SelectedValue).@visited = "Yes"
        xmlFile.Save(strPath)
End Sub


VB
defualt2.aspx

inside page_Load()
'MsgBox(System.Web.HttpContext.Current.Session("success")) ' o/p : Empty
Dim success As String = Session("success").toString
MsgBox(success) 'o/p : Empty
End Sub


1st Approach : Using Response
It Redirects to next Page properly but when I am trying to get Session value
It Shows Empty always..

2nd Approach : Using Server
I am afraid with this option, because It holds the session value and at the time of redirection it executes the Page_Load event of Default2.aspx but after page_load Control get destroyed and stays on my Default1.aspx (first page)

instead of Server.Execute I used Server.Transfer but it raise the Exception -" thread is being aborted"

Thanking you
Please show me way to rectify this problem
Posted
Updated 22-Apr-13 23:27pm
v5
Comments
Prasad Khandekar 19-Apr-13 6:08am    
What's the value of variable success? Are you storing a null value?
Rohit More 19-Apr-13 6:10am    
No , "success" is string variable and holds "Success" string.
Yuvaraj Arasu 19-Apr-13 6:49am    
Hi,Can you show that ," how you are getting session variable 'success' value at 'Default2.aspx' page ?"
Rohit More 19-Apr-13 7:16am    
yeah sure.

inside page_Load()
'MsgBox(System.Web.HttpContext.Current.Session("success")) ' o/p : Empty
Dim success As String = Session("success").toString
MsgBox(success) 'o/p : Empty
End Sub
Yuvaraj Arasu 19-Apr-13 8:03am    
I have tried with your method here, No problem and works fine.. Can you just print the Session.sessionid on both pages.. to check whether both ids are same.. check & inform us..

1 solution

try
C#
session["success"]="success";

beacause if you dont use quotes than success will be considered as a variable. Using this you can directly assign string to session.
 
Share this answer
 
Comments
Rohit More 19-Apr-13 7:44am    
Thank you for you kind reply Sir :),
but success is not direct String its String Variable....!
Thanks7872 19-Apr-13 7:45am    
have you tried debugging your code? what value you are assigning to that variable?can you show us the code you assigning the variable and retreiving the session at the redirected page?
Rohit More 19-Apr-13 7:50am    
default1.aspx
Dim success As String = "Success"
...
try
....
Session("success") = success
MsgBox(Session("success") ' O/p: Success
Response.Redirect("default2.aspx", False)
catch ex As Exception
MsgBox("Exception" + ex.Message)
End Try

defualt2.aspx

inside page_Load()
'MsgBox(System.Web.HttpContext.Current.Session("success")) ' o/p : Empty
Dim success As String = Session("success").toString
MsgBox(success) 'o/p : Empty
End Sub

Yes Sir I tried debugging, session get destroyed after redirection.
even I used that variable in multiple functions before redirection.
Thanks7872 19-Apr-13 7:56am    
have you assigned anywhere a session timeout?try direct assignment as i said before,and check the RETRIEVED value at second page by debugging.
Rohit More 19-Apr-13 8:07am    
well, as timeout concern I removed this but no change, and
about assigning direct string like Session("success")="Success", I tried before but no output.

The strange thing is that , as I mentioned above in my question,
when I use Server.Execute("default.aspx", false), It holds the Session values and even it do visit to another page (default2.aspx) Page Load event but it always shows default1.aspx page.
dont know why this? In default2.aspx does not contain any comparison and all kinds of stuff. there I am simply print Session variable and print "Thank you" message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900