form with "clear"

V

vinnie

i have a small form, with 5 labels and 5 textboxes (with 5 field
validators), plus 2 buttons.

Now, one of the buttons is the "CLEAR" one, and so if the user presses
the clear btn all the field should be reset to empty.
I have added the code to the page as it follows:

protected void Button1_Click(object sender, EventArgs e)
{
TextBoxName.Text = "";
TextBoxTelephone.Text = "";
TextBoxTitle.Text = "";
TextBoxMessage.Text = "";
TextBoxemail.Text = "";
}

however, if the user after completing two fields wish to clear all, it
happens that pushing the CLEAR btn the field validators blocks the
action.

What should add in to the code, to make the fieldvalidator to work
only on the send-button (or to not work for the clear-button)?

thanks,
Vinnie
 
P

Peter Duniho

vinnie said:
[...]
What should add in to the code, to make the fieldvalidator to work
only on the send-button (or to not work for the clear-button)?

I suppose you could include a flag that if not set, the validators all
just accept the data without checking it, and then set the flag when
clicking the "send" button.

That said, if you only want the data validated at a specific time, then
perhaps a better strategy is to not bother with validated fields and
just explicitly check all the data when the "send" button is pressed.

Pete
 
A

AreKc

vinnie pisze:
Now, one of the buttons is the "CLEAR" one, and so if the user presses
the clear btn all the field should be reset to empty.
I have added the code to the page as it follows:

protected void Button1_Click(object sender, EventArgs e)
{
TextBoxName.Text = "";
TextBoxTelephone.Text = "";
TextBoxTitle.Text = "";
TextBoxMessage.Text = "";
TextBoxemail.Text = "";
}

In Page_Init:

Button1.CausesValidation = false;
 

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