0

I have a couple of dropdown boxex in my aspx page and i have search button also.

if the user clicks the "search" button without selecting any of the dropdown box, i want to display message like "Please select any Value"

My Page is created dynamically, all the controls are dynamically created. and i dont want to display the error message using any of the static aspx page controls like (Text Box, label or etc...)

and I want to display the error message from some other .cs file which i am referring in my aspx.cs file.

I have tried like the below: However it is not working.

if (first!= "-- Select The Item --" || second != "-- Select The Item --")
            {
                //Do Something
            }
            else
            {

                throw new Exception("Please select any Filter Type");
            }
Jey
  • 2,137
  • 4
  • 22
  • 40

3 Answers3

1

You can use RequiredFieldValidator Please check below SO link:

How to add a RequiredFieldValidator to DropDownList control?

Community
  • 1
  • 1
Lajja Thaker
  • 2,031
  • 8
  • 33
  • 53
  • i need like say for ex: string a = "hi" if(a !=""){//do} else {show some message in the page} but am checking these thing my one my common .cs file, not in aspx.cs file – Jey Sep 10 '12 at 08:24
0

Assuming dd1 and dd2 are DropDownList control IDs, you could check the SelectedIndex property:

if (dd1.SelectedIndex != 0 || dd2.SelectedIndex != 0)
{
    //Do Something
}
else
{

    throw new Exception("Please select any Filter Type");
}
Curtis
  • 101,612
  • 66
  • 270
  • 352
  • i need like say for ex: string a = "hi" if(a !=""){//do} else {show some message in the page} but am checking these thing my one my common .cs file, not in aspx.cs file – Jey Sep 10 '12 at 08:25
0

Well javascript can be used to validate the drop down list....have a look at the link below How to validate dynamically created control?

Community
  • 1
  • 1
iJade
  • 23,144
  • 56
  • 154
  • 243