adding onchange javascript that fires after doPostBack ?

M

Mad Scientist Jr

I have some javascript I would like to run after a doPostBack occurs:

onchange="javascript:__doPostBack('Text1','');[my JavaScript here]"

The doPostBack is being added dynamically by .NET when it renders the
control.

If anyone can tell me how to tell .NET to add the doPostBack BEFORE
any javascript in the onchange event, it would be most appreciated.
 
J

John Saunders

Mad Scientist Jr said:
I have some javascript I would like to run after a doPostBack occurs:

onchange="javascript:__doPostBack('Text1','');[my JavaScript here]"

The doPostBack is being added dynamically by .NET when it renders the
control.

If anyone can tell me how to tell .NET to add the doPostBack BEFORE
any javascript in the onchange event, it would be most appreciated.

See if RegisterOnSubmitStatement works for you:
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfSystemWebUIPageClassRegisterOnSubmitStatementTopic.asp).
 
M

Mad Scientist Jr

See if RegisterOnSubmitStatement works for you:
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfSystemWebUIPageClassRegisterOnSubmitStatementTopic.asp).

I found another workaround - the answer to the whole thing ended up
being: turn off Smart Navigation. It was screwing everything up. I
couldn't set the values of server side controls from javascript, among
other things. The values would stay the same they were when the form
first initilaized. When I turned off smart navigation, these problems
went away.

To force focus to a particular control, I found this worked:

In the HTML body:

<body onload="javascript:eval(document.Form1.txtJavascript.value);">

In control's Autopostback event:

Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Text1.TextChanged
'(your code here)
'...
txtJavascript.Value = "document.Form1." & Text2.UniqueID &
".focus();"
End Sub ' Text1_TextChanged


Note: I haven't tried registerClientsideScript (or is it
registerStartupScript? I forget at the moment). They didn't work when
I had smartnavigation on but might with it off. Is this preferable to
the above method?
 
B

bruce barker

there is no reliable way. :__doPostBack does a form.submit(), which just
adds a request to the message queue, its not processed synchronously. also
when the response comes, all running script is canceled.

the window unload event may be what you want - its called when the response
causes the current window to unload

-- bruce (sqlwork.com)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top