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.
how did you add the javascript to your controls?
like so:
textbox1.attributes.add("onblur","checkme(self);"); ?
could you perhaps post some more code?
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
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
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
 
No comments:
Post a Comment