session variable gets empty after response.redirect

 Hi,

I am not getting why following things happening..

 

1. I have declared session variable in global.asax

2. Session("postrentattempt") = ""

3. In the page load of post rent page I am writing

           Session("postrentattempt") = "1"

            Response.Redirect("sellerlogin.aspx")

 4. Now, in sellerlogin, I am checking if             Session("postrentattempt") = "1" ?

  If yes---->Transfer to  postrent.aspx

  if No------> Transfer to sellerlogin.aspx

 5. And its transferring to sellerlogin.aspx 

 

why is it so?


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/12/2009 11:25:23 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

7 Replies
549 Views

Similar Articles

[PageSpeed] 43

Try this example:

 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Session("Value") = "1" 
    Response.Redirect("Page2.aspx") 
End Sub 

'Then on Page2.aspx 

'On page load you can get the value of your stored in the session variable 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
    If Session("Value") IsNot Nothing Then 
        If Session("Value").ToString() = "1" Then 
        'Do something 
        End If 
    Else 
        'Do something 
    End If 
End Sub
  
Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
1/12/2009 11:34:46 AM

Ok..i will try it


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/12/2009 11:38:36 AM

Hi,

I tried what you mentioned above for me its working fine with code as shown below

Session("postrentattempt") = "1"

If Session("postrentattempt") = "1" Then

Response.Redirect("postrent.aspx")

Else

Response.Redirect("sellerlogin.aspx")

End If

Output is postrent.aspx

I even chanhe the session value to 0 then output is sellerlogin.aspx

Thanks,

Farooq


Mark as answer if this post helpfull to you.

Don't be afraid to be wrong; otherwise you'll never be right.
0
susain
1/12/2009 11:44:12 AM

vinz:

Try this example:

 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Session("Value") = "1" 
    Response.Redirect("Page2.aspx") 
End Sub 

'Then on Page2.aspx 

'On page load you can get the value of your stored in the session variable 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
    If Session("Value") IsNot Nothing Then 
        If Session("Value").ToString() = "1" Then 
        'Do something 
        End If 
    Else 
        'Do something 
    End If 
End Sub

  

 

 

Still transferring to sellerlogin.aspx

here is my code ( please check) :

 

  If (Session("postrentattempt") IsNot Nothing) Then

                    If (Session("postrentattempt").ToString() = "1") Then
                        Response.Redirect("postrent.aspx")
                    Else
                        Response.Redirect("sellproperty.aspx")
                    End If
                Else
                    Response.Redirect("sellproperty.aspx")
                End If

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/12/2009 11:52:47 AM

Oh.....my mistake

in the page load i was writing this:

            Response.Redirect("sellerlogin.aspx") 

             Session("postrentattempt") = "1"

 

It should have been

             Session("postrentattempt") = "1"

            Response.Redirect("sellerlogin.aspx") 


 

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/12/2009 11:56:36 AM

Remove the Session declaration you created at global.asax file..


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
1/12/2009 11:56:38 AM

closeguy2005:

Oh.....my mistake

in the page load i was writing this:

            Response.Redirect("sellerlogin.aspx") 

             Session("postrentattempt") = "1"

 

It should have been

             Session("postrentattempt") = "1"

            Response.Redirect("sellerlogin.aspx") 

 

That's why it will always goes to that page since you are redirecting to the page before setting the Session values.. :D


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
1/12/2009 11:58:06 AM
Reply:

Similar Artilces:

Response.Redirect with Session Variable vs. Global Variable -- Best Practices?
Hi,I have a simple contact form and when the user presses the submit button an email is sent and  I have a response.redirect to "emailSent.aspx" where it says "Your request has been received....etc.".  I have the submit button in a try/catch block.  What I want to do is a "emailFailed.aspx" where it says "Email problem, etc." but I also want to carry over the ex.message text.  I want to pass the ex.error text to the "emailFailed.aspx" page so on pageLoad I can have a label with something like:labelMessage.Text = "There was a problem with your email.  The error is " +...

session variable is getting empty ?
hi , We hosted a asp.net application in our server. When we try to access the application  from other systems in network it's coming fine. When i connected a HP pavillion laptop with Windows vista and IE 7 .After i login when i click on a link to another page the session is getting timedout .Some how session is getting cleared . When i try in IE 6 .It's fine  But this session expiry is happening only in this laptop IF anybody knows this issue please help me   Thanks & Regards Are you using cookies for the session? If so are cookies turned off on the machine?...

Session Variables lost after Response.Redirect()
Hi gurus,  I encouter lost session variables trouble when Response.Redirect() to another aspx page. I set 19 Session variables before redirecting. However, the redirected page's session contains only One variable. The very weir sympton is: If I restart IIS, only for the first IE encounter, the redirected page DOES show all 19 session variables.Once I close IE, any further IE or IE from any other machine's only shows ONE session variable. I can also reproduce such symptons in VS2005 development environment. Can someone tell me what I have missed?   Thanks! Here is ...

Losing session variables after response.redirect
I'm using StateServer to manage my sessions. <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:1702" /> I then set the session values as follows on one page: Session("UserID") = dbReader("UserID")Session("FirstName") = dbReader("FirstName")Response.Redirect("~/member/Default.aspx") When it redirects to the next page, the session values are blank (null). I'm not sure at all what's happening. The IIS settings are fine as well. XP Pro, ASP.NET 2.0, IIS 5. There are too many protential reasons for session loss, and here is a newly post article on this, whi...

session variables in javascript on a web form
Hi All, I have master page on which I have written a javascript which open ups a new window when user clicks on menu item placed on the left side of master page. The javascript follows  function OpenWind()       {         <% if( HttpContext.Current.Session["Id"]==null) { %>                alert('Session Expired! Redirecting to login page!');           &nb...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Get response from non .net web service
I need to send xml request to web service serveras a HTTP POST requestwith content type of text/xmlthen, i need to save the content of the response which is also text/xml into .xml filehow can i do it in asp.net?please help server URL:http://text.xml.aot.com.au/xml2/ request:<?xml version='1.0' encoding='UTF-8'?><GetLocationsRequest>  <AgentID>DEMOBB</AgentID>  <Password>fatty2</Password>  <LocationType>T</LocationType>  <LocationCode>413</LocationCode></GetLocationsRequest>...

web form
I have a web form with some text boxes with validation to ensure that data has been entered. I have two buttons one for "submit" and one for "Return to main". When I click on submit - all works OK as it should with asking the user to enter data for the text boxes. However, when I click "Return to main", instead of redirecting to the main page, the validation requirements for the form appear. Here is some of my code... <table> <tr> <td valign="top" style="width: 318px"><asp:TextBox id="txtTextBox1" runat=&quo...

Forms Authentication
Hi I am creating a new Website Application that redirects the logged in user to a webpage based upon the role to which he belongs programatically in 'Authentication' event. I have designed the app. so that a User can belong to a single role at one time and I am using membership provider.  I have a web page that is stored in the rootfolder which is accessible by all users(including unauthenticated users). This webpage contains different menuitems and one of them is 'login'.  So If user A belongs to Role 'abc', he is redirected to a webpage in folder abc. S...

How to Response.Write Session variable into hidden form field
In classic ASP I often Response.Write a session variable's value into a hidden form field when passsing information to other sites (PayPal for example).  I have been unable to get the syntax to work in ASP.NET.  Can anyone tell me how to do this? The easy way is to wack a Label control onto your page. Let call it TheHiddenLabel.Assuming you know the session keyTheHiddenLabel.Text = "<input type='hidden' name='SessionKey' value='" + Session["SessionKey"].ToString() + "'>"; HTML elements are directly addressable in ASP.NET by adding runat="server" and an ID to them. Her...

Automatically fill in a web-form field-get response
Hi you all, I�d like to thank everyone that helped me with that little problem about filling in a webformfield and getting the result. I�d like to inform you, in case it comes to you... LWP::UserAgent really didn�t help me out, but www::mechanize solved all my problems, the script is up and running good! Thank you all! Diogo N Oliveira (brazilian) ...

Session variable between web forms and Data Access Layer
I am using ASP.NET 2.0 with c#. I am trying to declare a global session object that will be used in both c# Class files (DAl) and my web forms (Presentation Tier). Now my session object is Session["Bookid"].  The value stored in this session object is the value from a selected item in my dropdown control. That works fine. But I want this Session object to be used in a (DAL) but the value is null.  Here is exactly what i am trying to do. 1). Select item from dropdown control (from Web form)2). Assign the selected item to Session["Bookid"]3). Access that Session ...

getting start with vb.net and crystal repots(web form)
I use Crystal Report9 in Visual Studio.NET 2003..... Example at Northwind database I want a application that.....a form include a combobox that contain CustomerID.....If I choose one CustomerID and click OK button....a Report will display information about this Customer......I think that must use Paramater.....how to do that ???? (How do I start to coding --please step by step or sample) please help me !!! Thank you so much!!! very good I have Dropdownlist when I choose the 'month'--> the all data of this field will show I use this Private Sub ddlMonth_Sel...

How to Debug Response.Redirect losing session variable, when upload file
HELP! I have a page where users can enter text and optionally upload an image. To upload the image, the page contains an image file upload usercontrol I created. The control displays the image after loading and stores the image information to the database and creates an image ID. Then the user can submit the entire page which just saves the user's text and the image ID to the database. In addition, I create a user account for the user and store their new id in a session variable ("LoginID"). When saved, the page does a response.redirect to the next data input page. Excluding the first pag...

Web resources about - session variable gets empty after response.redirect - asp.net.web-forms

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

YouTube v10.32 Tweaks Some Interface Elements And Includes Hints About Virtual Reality Content And Variable ...
Forget Update Wednesday! Monday is the new big day. Not only were we treated to the latest M preview release and the official Marshmallow name, ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Cisco Debuts Open Pay Variable Pricing, Updates CCRE
Cisco Debuts Open Pay Variable Pricing, Updates CCRE Channel Partners Kris Snow, president of Cisco Capital, says the company's new Open Pay ...

Expert Reveals the Latest Variable Capacity Technology
Learn about gForce Ultra CRAC equipment, the latest variable capacity technology to lower energy usage and increase reliability.

Resources last updated: 11/21/2015 7:10:25 PM