C# Form Processing: If Exists

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
 
C

Cowboy \(Gregory A. Beamer\)

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.
 
M

Matthew Loraditch

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top