Response.Redirect with Session Variable vs. Global Variable -- Best Practices?


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 " + ex.message;

I was thinking of storing the ex.message as a string -- but then I didn't know whether to put in a global varialbe or a session variable so I can easily pass it to the "emailFailed.aspx" page.

Thanks in advance! 


2/23/2007 2:03:29 AM 8807 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 46
Get it on Google Play
Get it on Apple App Store

Actually I would use Server.Transfer instead of Response.Redirect so you still have access to the label
My Blog
Please click on 'Mark as Answer' if this post answered your question!
2/23/2007 2:33:26 AM

try this

            'your code goes here 
            Response.Redirect("emailSent.aspx", True)
        Catch ex As Exception
          'erro happened
            Session("ex") = ex
            Response.Redirect("emailFailed.aspx", True)
        End Try

and in the emailFailed.aspx page_Load function

write this:

dim ex as exception=session("ex")
if not  ex is nothing
labelMessage.Text = "There was a problem with your email.  The error is " + ex.message;
end if


Anas Ghanem.

Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

2/25/2007 9:12:54 AM

Similar Artilces:

Session variables vs. Session States
What is the difference and in what situations are they used. Thanks, Mattypee A session state (the state of your session) holds your session variables. If your session state expires (due to inactivity) then you lose your session variables...and any other info stored for that session. If you need to store USER specific information within a web app, then session variables are one(of several) ways to do it. MajorCatsMajorCats Is there any code that you could show that would give an example? Thanks, Mattypee example of what? reading and writing session variables? ...

Opinions on Viewstate vs. Session variable for state management on dataset
I came across many sample codes that using ViewState(myDataSet) and Session("myDataSet"). Which is a better way to use to keep the session around. What are the pros and cons? Anybody can share with your experience or thoughts? Thanks, teresa Take a loot at this article: State Management in Web Forms Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!...

Passing variables vs session variable
what is the advantage of passing the variable in the url vs storing the variable in a session variable and retrieving it in the second webpage you are accessing?  The variable that you will pass using the QueryString will be visible to the user hence not secured. The value that you put in the Session is not available to the user as it is on the server side and hence more secured. HighOnCodingWanna get high! performance wise does it matter? Just my 2 cents... I remember in college the professors would always harp upon using the Session responsibly. Most of the professors were old...

Cache Variable vs. Session Variable
I'm anxious to get some feedback with regard to using a cache variable in lieu of a session variable. My research tells me that caching is the way to go for maintaining state on datasets. However, I've only seen the cache variable discussed as an alternative to an application variable (as opposed to the session variable). I'm actually exploring the idea using of using a cache variable as an alternative to a session variable for maintaining state on a dataset specific to each user (Each user is able to select the fields they wish to view; the user will then be able to page and sort on th...

global variable vs local variable
hi all, i have a scenario like function is called more than 1000 that function i declared a varible and assigning a value .i felt like declare a global varible use it in that function and assign value.which is best.please tell me in performance point of view. thanks in advance  Hai Good Morning you have call  the function  more than 1000 times Better use Global variables, so you can call the function, anywhere.. it has good performance.suppose it you want assign different values to the variables , whenever the function has been called for that use local ...

global variable/object without session or application variable
Hi All, I have 1 or more dynamically assigned user controls. Now i need to pass a user control's value to another user controls during page load. We can do using session variable, but the problem over here is it would slow down my application. So i would like to attain this without using the session or application variable. Please let me know if you have any questions. Thanks, thiyaThank you in advance. I am pleased to return the favor. Read this post.Jared - Livingston Family WebsiteTest/Demo site - Reviewed the posted reply. That one...

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 ...

variable variables?
Hello! How to make a variable receive an increment in the name? I want to do it for example: I have: Label1->Caption = "1"; Label2->Caption = "2"; Label3->Caption = "3"; Label4->Caption = "4"; And I want to do something like that: for (i=1; i<5; i++) { Label+i->Caption = i; } Any idea? Can I do something like that? Thanks and regards Alexandre Create a vector of pointers to the various objects. In your case below, construct a vector (called Labels) of pointers to TLable long enough to hold pointers to...

Losing session variables after response.redirect
I'm using StateServer to manage my sessions. <sessionState mode="StateServer" stateConnectionString="tcpip=" /> 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...

Variable Variables
Hi, Maybe the solution is very simple, but how do I create variable variables in I want to use the value of a variable as a part of the name of another variable. A very simple example below: code: Dim a As String a = "1" Label a.Text = "hi" page: <asp:Label id="Label1" runat="server">Label</asp:Label> In need this to change a range of values by using just one loop. I can´t do that without creating a variable variable name. Hi, check out this little demo application I created for you: ...

Session State variable missing after Redirect
When an error occurs, I set a session variable so that after redirecting to an error page, a detailed explanation can appear.  The variable (a string) is gone by the time I reach Page_Load in the target page.  I've checked and it is the same session ID. Any ideas? Are Sessions enabled? Are you forwarding to a page outside of you application?View My Blog Download My URL Rewriter and Reverse ProxyOnly $9.95/month, ASP.NET, 2GB & SQL 2005...

variable not a variable
Error:Must declare the variable '@cartDateTime'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@cartDateTime'. Dim connStr As SqlConnection            Dim cmdInsert As SqlCommand            Dim strInsert As String      &n...

variable of variables
Say I have 2 scenarios and I want to use a different variable depending on which scenario applies without coding this logic. So I could have a database table t_variables which has: Scenario: Variable: --------- -------- 1 v_name 2 v_company In my Powerbuilder code I'd have values in v_name & v_company. What I'd like to be able to do is to select which variable to use from the table and assign that to something, e.g. select variable into v_variable from t_variables where scenario = 1 so at this point v_variable would be 'v_name'...

Global Variables vs. instance variables declared at application object level
There is only one application object instance during the application runtime that is instantiated at the start along with the global variables, so I am looking for what are the major differences, advantages , and disadvantages between Global Variables and instance variables declared for the application object. Thanks I've wondered also about the application instance variables. I think the difference with global vars is very subtle. Maybe too subtle to be of any use. Anyway, you shouldn't be using either one of them :-) Geert 'Darling' Van Damme Moh...

Public Shared variable vs. application state variable -- exactly identical??
I've done several searches on this topic in the forums here, but I'm still not 100% sure I know the answer to this question: is declaring a public shared variable in global.asax the same thing as using Application("xxx")? If so, is there any reason to use Application state variables at all when you can get all the benefits (eg. code completion) of using the public shared variable? Thanks, Steve I just found this blurb in a Ask Dr. Gui.NET article on MSDN and now I'm more confused than before: An important note: while it's just fine to use static/Shared methods in ASP.NE...

Web resources about - Response.Redirect with Session Variable vs. Global Variable -- Best Practices? -

Admission to practice law - Wikipedia, the free encyclopedia
An admission to practice law , also called admission to the bar in some jurisdictions, is acquired when a lawyer receives a license to practice ...

Drug dealer Simon Main mentioned in case of shooting at Double Bay cosmetic dentistry practice
An &quot;international drug dealer of renown&quot; has been mentioned in the case of a shooting at a Double Bay cosmetic dentistry practice. ...

What A F*cking Terrible Niche Practice
Pulling this beat has to be depressing as hell particularly right before the holidays.

NY Attorney General investigating T-Mobile for false advertising and ‘abusive’ practices
T-Mobile has turned the U.S. wireless industry on its head over the past few years, forcing larger rivals to respond to its every move. With ...

Review: Exploring the Practice of Antifragility
I wrote a review on Amazon for Exploring the Practice of Antifragility . I am republishing it here: First disclosure: As of the 5 th of December ...

Iowa teen dies after collapsing at basketball practice
Authorities say the 16-year-old boy died less than five days after collapsing during basketball practice

Consumer Advocates Ask Regulators To Investigate T-Mobile Over Advertising, Debt Collection Practices ...
... not necessarily realize that they are responsible for the balance on the EIP if they cancel, but also T-Mobile’s debt collection practices are ...

Syed Rizwan Farook’s Dating Profile Shows He Liked Reading ‘Religious Books’ And Shooting Target Practice ...
Syed Rizwan Farook’s Dating Profile Shows He Liked Reading ‘Religious Books’ And Shooting Target Practice

Watch the Patriots practice in VR through Google Cardboard
You can't currently get a first-hand experience of an NFL game short of becoming a football star and strapping on a helmet, but Bank of America ...

An Exceptional Insight Into Commercial Bribery Practices At British American Tobacco
The BBC acquired hundreds of documents which purportedly show that British American Tobacco paid bribes to politicians, public officials and ...

Resources last updated: 12/9/2015 8:23:28 PM