?
Solved

Condition is never met when no queryString is presented

Posted on 2013-05-20
3
Medium Priority
?
261 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
[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 36

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 36

Accepted Solution

by:
Miguel Oz earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 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