C# Form Processing: If Exists

Discussion in 'ASP .Net' started by Matthew Loraditch, Nov 21, 2007.

  1. I have several different variations of the same form. Some include an asp
    Radio Button list option called rb_monthly. If that option exists I need to
    do some extra processing on the form.
    The following works on the pages with the option :
    if(rb_monthly != null)
    {
    monthly = rb_monthly.SelectedValue;
    }

    When the option's not there it doesn't work and I get compiler errors as
    rb_monthly doesn't exist.
    I've tried this:
    string valMonthly = findVals("rb_monthly");
    if (valMonthly != "")
    {
    monthly = valMonthly;
    }
    and some variations thereof, and while that doesn't cause compiler error it
    also doesn't get the value and fails to process a later section of the code
    that is supposed to process if monthly is true.

    There has gotta be some way to do some sort of if exists check but I'm
    mostly a newbie and am working off code I have been given.
    Any help is majorly appreciated!!!
    Thanks
    Matthew Loraditch
     
    Matthew Loraditch, Nov 21, 2007
    #1
    1. Advertising

  2. Check for null, as well, as a string can be null. That is quite common,
    especially when pulling from a keyed list, like the ASP.NET form or
    querystring collections.

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    *************************************************
    | Think outside the box!
    |
    *************************************************
    "Matthew Loraditch" <> wrote in message
    news:...
    >I have several different variations of the same form. Some include an asp
    >Radio Button list option called rb_monthly. If that option exists I need to
    >do some extra processing on the form.
    > The following works on the pages with the option :
    > if(rb_monthly != null)
    > {
    > monthly = rb_monthly.SelectedValue;
    > }
    >
    > When the option's not there it doesn't work and I get compiler errors as
    > rb_monthly doesn't exist.
    > I've tried this:
    > string valMonthly = findVals("rb_monthly");
    > if (valMonthly != "")
    > {
    > monthly = valMonthly;
    > }
    > and some variations thereof, and while that doesn't cause compiler error
    > it also doesn't get the value and fails to process a later section of the
    > code that is supposed to process if monthly is true.
    >
    > There has gotta be some way to do some sort of if exists check but I'm
    > mostly a newbie and am working off code I have been given.
    > Any help is majorly appreciated!!!
    > Thanks
    > Matthew Loraditch
     
    Cowboy \(Gregory A. Beamer\), Nov 21, 2007
    #2
    1. Advertising

  3. Sorry for the newb questions.
    Right now I am doing this, but as I previously mentioned, it only works if
    the rb_monthly is on the page:
    if(rb_monthly != null)
    {
    monthly = rb_monthly.SelectedValue;
    }
    Are you saying do this?
    if (rb_monthly == null)
    {
    monthly =false;
    } else{
    monthly = rb_monthly.SelectedValue;
    }

    Thanks again,
    Matthew

    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:#...
    > Check for null, as well, as a string can be null. That is quite common,
    > especially when pulling from a keyed list, like the ASP.NET form or
    > querystring collections.
    >
    > --
    > Gregory A. Beamer
    > MVP, MCP: +I, SE, SD, DBA
    >
    > *************************************************
    > | Think outside the box! |
    > *************************************************
    > "Matthew Loraditch" <> wrote in message
    > news:...
    >>I have several different variations of the same form. Some include an asp
    >>Radio Button list option called rb_monthly. If that option exists I need
    >>to do some extra processing on the form.
    >> The following works on the pages with the option :
    >> if(rb_monthly != null)
    >> {
    >> monthly = rb_monthly.SelectedValue;
    >> }
    >>
    >> When the option's not there it doesn't work and I get compiler errors as
    >> rb_monthly doesn't exist.
    >> I've tried this:
    >> string valMonthly = findVals("rb_monthly");
    >> if (valMonthly != "")
    >> {
    >> monthly = valMonthly;
    >> }
    >> and some variations thereof, and while that doesn't cause compiler error
    >> it also doesn't get the value and fails to process a later section of the
    >> code that is supposed to process if monthly is true.
    >>
    >> There has gotta be some way to do some sort of if exists check but I'm
    >> mostly a newbie and am working off code I have been given.
    >> Any help is majorly appreciated!!!
    >> Thanks
    >> Matthew Loraditch

    >
    >
     
    Matthew Loraditch, Nov 21, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Totan
    Replies:
    0
    Views:
    1,079
    Totan
    Apr 17, 2006
  2. Jukka K. Korpela
    Replies:
    3
    Views:
    793
    Michael Winter
    Mar 6, 2004
  3. Michael Winter
    Replies:
    4
    Views:
    621
    Lasse Reichstein Nielsen
    Mar 6, 2004
  4. Robert
    Replies:
    0
    Views:
    528
    Robert
    Mar 6, 2004
  5. Ulf Meinhardt
    Replies:
    8
    Views:
    6,304
Loading...

Share This Page