can help me with message box in C#.net

Y

yefei

i want to display a message box when the user click the submit buttone,
but some fields are not filled(those fields are which can not be
validated using available validators)
i know in C#.net, the asp doesnot support messagebox class
and I also cannot add the System.Windows.Forms namespace
can anyone give a sample of inserting a javascript to do this?
the alert message will vary depends on what field is not filled?
if I cannot check all the fields using one function, also can use one
function for each field.
thanks
 
T

Truong Hong Thi

You can use the "alert(text)" javascript method to show message box
for client-side validation. However, the recommend way is using
CustomValidator. Use its ClientValidationFunction method to register a
client validation javascript method.
Check out MSDN/Google.
 
T

Truong Hong Thi

Pure javascript is not enough (what if user turns off js, or even
modify the js code). Server validation should always be performed.
CustomValidator makes validation easier by providing design time
support, how to display the error message, etc. It is similar to other
available validators.
 
Y

yefei

but for custiom validator, the control to validate can only set to
textbox, radiobuttonlist, dropdownlist, etc, but not check box and
another situation that I want to check is I need user to input either
handphone or telephone number.
I am not sure about the custom validation function,
can anyone give an example of checking a property of a control in the
validation function?
 
Y

yefei

ok
I got the solution
for customValidator, no need to set the controlToValidate
if you want to run server validate
go to events
here is my code for my problem
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = (CheckBox1.Checked == true);
}
protected void CustomValidator2_ServerValidate1(object source,
ServerValidateEventArgs args)
{
args.IsValid = (dropDownListSchool.SelectedIndex > 0);
}
protected void CustomValidator3_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (textBoxTel.Text == "" & textBoxHandphone.Text == "")
args.IsValid = false;
else
args.IsValid = true;
}

hope this will help people with same problem
 

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

Top