adding onchange javascript that fires after doPostBack ?

Discussion in 'ASP .Net' started by Mad Scientist Jr, Jul 15, 2004.

  1. 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.
    Mad Scientist Jr, Jul 15, 2004
    #1
    1. Advertising

  2. "Mad Scientist Jr" <> wrote in message
    news:...
    > 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).
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jul 15, 2004
    #2
    1. Advertising

  3. > 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?
    Mad Scientist Jr, Jul 15, 2004
    #3
  4. Mad Scientist Jr

    bruce barker Guest

    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)

    "Mad Scientist Jr" <> wrote in message
    news:...
    > 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.
    bruce barker, Jul 15, 2004
    #4
    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. =?Utf-8?B?RFNpcHA=?=

    javascript dopostback fails

    =?Utf-8?B?RFNpcHA=?=, Jan 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,594
    David Jessee
    Jan 20, 2005
  2. TJS
    Replies:
    7
    Views:
    622
  3. =?Utf-8?B?Q2VzYXI=?=

    adding extra code to the doPostBack function

    =?Utf-8?B?Q2VzYXI=?=, Jun 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,502
    Craig Deelsnyder
    Jun 16, 2005
  4. Replies:
    3
    Views:
    991
  5. Mel
    Replies:
    1
    Views:
    105
    scripts.contact
    Apr 3, 2007
Loading...

Share This Page