UpdatePanel and OnBlur

Last post 03-12-2007 10:38 PM by SuperGhost. 4 replies.

Sort Posts:

  • UpdatePanel and OnBlur

    03-12-2007, 6:15 PM
    • Loading...
    • SuperGhost
    • Joined on 12-29-2005, 11:58 AM
    • Palmdale CA, USA
    • Posts 404

    Background: I have a script which attaches event listeners to OnFocus and OnBlur of my form controls after the page has loaded. The script updates a DIV with information about the element when focused and resets the DIV when blurred. My controls are wrapped inside an UpdatePanel.

    The Problem: After the AsyncPostBack has occured my event listeners no longer work. The page is meant to redirect if all the fields are valid, so I am using validators - if the page is invalid it will not redirect and it is at this point that the event listeners stop working.

    The Questions: Why are my event listeners not working after the AsyncPostBack? Is there a way to permanently register an event listener?

    Also, now that I think about it... Are my validators overwriting the events? The validators only do custom server-side validation, no client-side.

    ** Hope this helps!

    DennyDotNet.com
  • Re: UpdatePanel and OnBlur

    03-12-2007, 7:47 PM

    how did you add the javascript to your controls?
    like so:
    textbox1.attributes.add("onblur","checkme(self);"); ?


    could you perhaps post some more code?

    please mark answers as 'Answered' and post back solutions when you figure stuff out.

    join www.floxtar.com: the first community where YOU help make a difference! Support a good cause and it doesnt cost you a thing!
  • Re: UpdatePanel and OnBlur

    03-12-2007, 8:08 PM
    • Loading...
    • SuperGhost
    • Joined on 12-29-2005, 11:58 AM
    • Palmdale CA, USA
    • Posts 404

    I'm using javascript to gather all my form fields and add the listeners through the javascript. This works just fine, my code executes correctly. The problem is right after an AsyncPostBack.

    My javascript load:

    var fh = new formHelper();
    fh.form = 'fm';    // Starting element
    fh.divDisplay = 'divNote';    // DIV to display info
    fh.helpForm();    // Load the event handlers

    This is what adds the event handlers (this uses Prototype)

                    // Add event handler
                    if (elementsFound[x].title.length > 0) {
                        Event.observe(elementsFound[x], 'focus', this.getElementNote.bindAsEventListener(this));
                        Event.observe(elementsFound[x], 'blur', this.getElementNote.bindAsEventListener(this));
                    }

    Everything works until the AsyncPostBack. My update panel is set to conditional and trigger is set to my btnSubmit.Click

    ** Hope this helps!

    DennyDotNet.com
  • Re: UpdatePanel and OnBlur

    03-12-2007, 8:17 PM
    Answer
    I see..I had the exact same problem, but couldnt get it to work..
    check here, perhaps it does help you: http://forums.asp.net/thread/1545416.aspx

    if not I suggest you attach the javascript code via the attributes.add method..(if possble)

    HTH
    please mark answers as 'Answered' and post back solutions when you figure stuff out.

    join www.floxtar.com: the first community where YOU help make a difference! Support a good cause and it doesnt cost you a thing!
  • Re: UpdatePanel and OnBlur

    03-12-2007, 10:38 PM
    Answer
    • Loading...
    • SuperGhost
    • Joined on 12-29-2005, 11:58 AM
    • Palmdale CA, USA
    • Posts 404

    I managed to find a way to accomplish it.

    In my btnSubmit_Click before I do the page.isValid check I re-register the script through the ScriptManager: 

    ScriptManager.RegisterStartupScript(btnSubmit, Page.GetType(), "fh", _
        "var fh = new formHelper();fh.form = 'fm';fh.divDisplay = 'divNote';fh.helpForm();", _
        True)
     Thanks for helping me get started in the right direction

    ** Hope this helps!

    DennyDotNet.com
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter