if statement dosen't parse properly [Answered]RSS

2 replies

Last post Jul 09, 2010 01:59 PM by HumanCompiler

  • if statement dosen't parse properly

    Jul 07, 2010 11:52 PM|rickj1|LINK

    I did this tutorial

    http://www.asp.net/webmatrix/tutorials/1-getting-started-with-webmatrix-and-asp-net-web-pages

    it uses this if statement

    <div>

    @if (Request["TwitterUser"] == null) { @Twitter.Profile("microsoft")

    }

    else {

    @Twitter.Profile(Request["TwitterUser"])

    }

    </div>

     when I first load the page the Twitter feed is from microsoft when I type another name

    that feed comes up fine but when I click on submit with empty text I get the yellow screen of death

    with this exception

    Line 26:             else { 
    Line 27:
    Line 28:                 @Twitter.Profile(Request["TwitterUser"]) 
    Line 29:
    Line 30:             }

    [ArgumentException: Value cannot be null or an empty string
    Parameter name: twitterUserName]
       Microsoft.WebPages.Helpers.Twitter.Profile(String twitterUserName, Int32 width, Int32 height, String backgroundShellColor, String shellColor, String tweetsBackgroundColor, String tweetsColor, String tweetsLinksColor, Int32 numberOfTweets, Boolean scrollBar, Boolean loop, Boolean live, Boolean hashTags, Boolean timestamp, Boolean avatars, String behavior, Int32 searchInterval) +454
       ASP.index_cshtml.Execute() in c:\Users\Owner\Documents\My Web Sites\HelloWorld\index.cshtml:28
       Microsoft.WebPages.WebPageBase.ExecutePageHierarchy() +152
       Microsoft.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase initPage) +33
       Microsoft.WebPages.WebPageHttpHandler.ProcessRequest(HttpContext context) +337
    

    Beta Junky
    www.barterlinks.net
  • Re: if statement dosen't parse properly

    Jul 08, 2010 12:18 AM|KristoferG|LINK

    The error is on line 28, which means that Request["TwitterUser"] is not null. Instead, my guess is that it is an empty string. The error message also indicate that Request["TwitterUser"] is either null or an empty string (but we have alreade ruled out that is null. So try to modify your code to the following:


    @if (Request["TwitterUser"] == null || Request["TwitterUser"] == "") {

        @Twitter.Profile("microsoft")

    }

    else {     @Twitter.Profile(Request["TwitterUser"])

    }

    Kristofer Gafvert

    http://www.it-notebook.org
  • Re: if statement dosen't parse properly

    Jul 09, 2010 01:59 PM|HumanCompiler|LINK

    Yes, there was a typo.  If you go back and look again you'll see it's been fixed.  The initial if statement should read like this instead...

    @if (Request["TwitterUser"].IsEmpty()) {

    Erik Porter
    ASP.NET PM
    http://about.me/erikporter