C# Form Processing: If Exists

  • Thread starter Thread starter Matthew Loraditch
  • Start date Start date
M

Matthew Loraditch

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
 
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!
|
*************************************************
 
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
 
Back
Top