Reputation: 333
How can I check a dropdownlist is existed on a page or not? I want to validate a certain condition when there is no dropdownlist found on the page. If it cant find any dropdownlist, it will not run the code string test = DropDownList1.SelectedItem.Text.ToString();
What i've tried:
if (DropDownList1 not exist)
{
//
}
string test = DropDownList1.SelectedItem.Text.ToString();
Upvotes: 0
Views: 57
Reputation: 496
if (DropDownList1 != null)
{
string test = DropDownList1.SelectedItem.Text.ToString();
}
Or alternatively:
if (DropDownList1 == null)
{
//Do stuff
return;
}
string test = DropDownList1.SelectedItem.Text.ToString();
Upvotes: 1