Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

864 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

23 Experts available now in Live!

Get 1:1 Help Now