Add onclick attribute to image button still puts javascript postback function

Discussion in 'ASP .Net' started by Boricua, Nov 16, 2006.

  1. Boricua

    Boricua Guest

    I'm using ASP.NET 2.0

    I got an imagebutton at the end of my form as a submit button. When
    the user clicks it the button becomes disabled and continues with the
    postback.
    This is what I got, ib is the imagebutton.
    Dim sbValid As New StringBuilder()
    sbValid.Append("if(typeof(Page_ClientValidate)=='function'){ ")
    sbValid.Append("if (Page_ClientValidate() == false) { return
    false; }} ")

    sbValid.Append("this.disabled = true;")

    Dim myPostBackOptions As New PostBackOptions(ib)
    myPostBackOptions.PerformValidation = True


    sbValid.Append(ClientScript.GetPostBackEventReference(myPostBackOptions))
    sbValid.Append(";")
    'ib.Attributes.Add("onclick", sbValid.ToString())

    ib.OnClientClick = sbValid.ToString()

    This is my problem: This works fine in IE. Firefox on the other hand
    I noticed that the button when click posted back twice. Looking at the
    rendered source code I noticed that the postback function in the
    onclick attribute of the image button is there twice. I presume that
    ASP.NET is adding it to the end of my javascript. How to stop it from
    doing this?

    I went ahead and comment out the code that adds the postback function
    (lines: 7-11). Worked fine in firefox but broke IE. I was thinking of
    wrapping that code with an if statement (if browser = IE), but I am not
    sure what happens if the browser is Opera, Safari or others so I
    decided not to go that route.

    So is there a way to tell asp.net not to add javascript postback
    function to onclick attribute. That way i can just added myself.

    Thank you

    Rick
     
    Boricua, Nov 16, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Taylor
    Replies:
    2
    Views:
    14,672
    maclade
    Mar 20, 2008
  2. Smash
    Replies:
    3
    Views:
    392
    Elton Wang
    Feb 21, 2005
  3. Michael Brooks
    Replies:
    22
    Views:
    440
    Rick DeNatale
    Mar 27, 2007
  4. Raj Singh
    Replies:
    4
    Views:
    156
    Ryan Ingram
    Jan 29, 2008
  5. Replies:
    2
    Views:
    285
Loading...

Share This Page