Solved

passing variable to nother page via query string using Response.Redirect

Posted on 2011-09-18
3
275 Views
Last Modified: 2012-05-12
I  am getting the eventid in page load method. I need to pass this event id  on the click of the button  to the page mentioned in the code snippet.   I am getting the syntax.  What is the correct way of doing this.

Urgently required.
see  attached code snippet
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim eventID As String = Session("EventID").ToString
        Response.Redirect("Seminar_Information.aspx?eid='" + eventID + "'")

    End Sub

Open in new window

0
Comment
Question by:Ammar Iqbal
  • 2
3 Comments
 
LVL 3

Expert Comment

by:a_hassaan
ID: 36556354
Try the code below, but just know that you can access the same session variable in your Seminar_Information Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim eventID As String = Session("EventID").ToString
        Response.Redirect("Seminar_Information.aspx?eid=" + eventID)
    End Sub

Open in new window

0
 
LVL 3

Expert Comment

by:chandrasekar1
ID: 36556429
hassaan is right, you can also added extra check to validate the session is empty or not, in this way we can avoid the exception at runtime, if session is not there or null

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
If Session("EventID") <> "" AndAlso Session("EventID") IsNot Nothing Then
            Response.Redirect("Seminar_Information.aspx?eid=" + Session("EventID").ToString)
        End If
End Sub
0
 
LVL 3

Accepted Solution

by:
a_hassaan earned 500 total points
ID: 36556505
if you are going to apply chandrasekar1 method, which is the best practice, then you should check for null reference before comparing the object to empty string, while using AndAlso guarantees that the next part of the logical comparison will not be evaluated in case the first part failed, to avoid runtime exceptions, so your code should look like:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  If Not isNothing(Session("EventID"))AndAlso Session("EventID") <> "" Then
    Response.Redirect("Seminar_Information.aspx?eid=" + Session("EventID").ToString)
  End If
End Sub

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question