Solved

Condition is never met when no queryString is presented

Posted on 2013-05-20
3
210 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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