Results 1 to 5 of 5

Thread: Using Validator cancels my use of attribut

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    43

    Question 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

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Using Validator cancels my use of attribut

    Code:
    button2.CausesValidation = false;

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    43

    Re: Using Validator cancels my use of attribut

    This will make them both work?? The validation and the messagebox?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  5. #5
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    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.
    Last edited by axion_sa; Mar 8th, 2005 at 12:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width