Solved

Condition is never met when no queryString is presented

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 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