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
Solved

Condition is never met when no queryString is presented

Posted on 2013-05-20
3
238 Views
Last Modified: 2014-01-25
Either none of these will be presented or one will be presented. When none is presented the condition is never hit

        Private _page As String = HttpUtility.UrlEncode(HttpContext.Current.Request.QueryString("Page"))
        Private _pge As String = HttpUtility.UrlEncode(Page.RouteData.Values("page"))

         Private Function getPage() As String
            Dim ret As String = ""
            If String.IsNullOrEmpty(_page) = True AndAlso String.IsNullOrEmpty(_pge) = True Then
                ret = 1
            ElseIf String.IsNullOrEmpty(_page) = False AndAlso String.IsNullOrEmpty(_pge) = True Then
                ret = _page
            ElseIf String.IsNullOrEmpty(_page) = True AndAlso String.IsNullOrEmpty(_pge) = False Then
                ret = _pge
            End If
            Return ret
        End Function

Open in new window

0
Comment
Question by:ruffone
  • 2
3 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 39183872
Your if logic is not covering the following condition
String.IsNullOrEmpty(_page) = False AndAlso String.IsNullOrEmpty(_pge) = False

thus ret is set to "" as none of the if logic conditions is fired.
0
 
LVL 4

Author Comment

by:ruffone
ID: 39184547
when I made this the second call the third and fourth condition no longer  got met. When I made it the last condition I got this error on the pge declaration

Overload resolution failed because no Public 'UrlEncode' is most specific for these arguments:
    'Public Shared Function UrlEncode(str As String) As String':
        Not most specific.
    'Public Shared Function UrlEncode(bytes As Byte()) As String':
        Not most specific.
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 39185937
Page.RouteData.Values("page") can return a null value that can not be processed by UrlEncode, thus you need to check for it as shown below:
If Page.RouteData.Values("page") is Nothing then
   _pge = ""

Open in new window

Note: you can put this code on Page_Load event before calling GetPage method.

Check :
http://stackoverflow.com/questions/13783675/check-if-page-routedata-values-has-a-value
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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