Solved

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

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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

624 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