Using Validator cancels my use of attribut
Hello everyone !!
This is my problem, Im justing a alert to ask the user to if he is realy sure to delete something. If he clicks ok it is delete of not, nothing happens.
Everything was fine so far.
(btw I'm talking about a code behinde page combined with asp.net)
This is how I lanch the popup
Code:
Button2.Attributes.Add("OnClick","return confirm('Are you sure you want to delete the item?')");
So I add an Attribiute to my button.
Next I use a RequiredFieldValidator to check if a textbox is fill in.
Code:
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
and in my asp page
Code:
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
Now the problem is, that the validation works, but one way or an other it cancels the pop up.
Does someone know what the problem is , or if there is a way to use them both at the same time?
Greetzz ChenZy
Re: Using Validator cancels my use of attribut
Code:
button2.CausesValidation = false;
Re: Using Validator cancels my use of attribut
This will make them both work?? The validation and the messagebox?
Re: Using Validator cancels my use of attribut
Just a hunch, but try this:
Code:
Button2.Attributes.Add("OnClick","return confirm('Are you sure you want to delete the item?');");
(note the semicolon)
Although I think that if you're going to do two things for one element, they should be combined. So you could validate and confirm in your own javascript function.
Re: Using Validator cancels my use of attribut
Quote:
Originally Posted by Draven Chen Zhen
This will make them both work?? The validation and the messagebox?
Any reason why you want to force the user to enter valid information when they're going to delete the record? ;)
On a related note, when a button causes validation, the .Net framework will automatically render "if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();" within the "onClick" client side event; clearing any user defined code in the process. Thus, your confirmation will not work if <DeleteButton>.CausesValidation is set to true.