Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

Condition is never met when no queryString is presented

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
ruffone
Asked:
ruffone
  • 2
1 Solution
 
Miguel OzSoftware EngineerCommented:
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
 
ruffoneAuthor Commented:
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
 
Miguel OzSoftware EngineerCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now