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");
            }
0

3 Answers 3

1

You can use RequiredFieldValidator Please check below SO link:

How to add a RequiredFieldValidator to DropDownList control?

Sign up to request clarification or add additional context in comments.

1 Comment

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
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");
}

1 Comment

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
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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.