Solved

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

Posted on 2011-09-18
3
267 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now