Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-18
3
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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