Run Server-side Function *immediately after* executing client-side JavaScript.

Discussion in 'ASP .Net' started by Guadala Harry, Jun 13, 2004.

  1. Suppose I have a hyperlink that, when clicked, executes a JavaScript
    function on the client. Separately I have a button that, when clicked,
    causes a post back and executes a server-side function, as in the following:

    <a id="HyperLink5" href="javascript:DoSomethingInClient()">Do Something</a>

    <asp:Button id="btnSaveChanges" EnableViewState="true"
    CommandName="SaveChanges" Visible="true" Width="115" runat="server"
    Text="Save Changes"></asp:Button>

    What I want is to have it so that when the user clicks on the hyperlink, the
    JavaScript function executes and then the PostBack gets initiated
    immediately after the JavaScript function does its thing - as if the user
    had clicked on the Save Changes button (but without requiring the user to
    click on the button). That is, I want the JavaScript to make its client-side
    changes and then cause the server-side "Save Changes" function to execute.
    Any ideas?

    Thanks!
     
    Guadala Harry, Jun 13, 2004
    #1
    1. Advertising

  2. "Guadala Harry" <> wrote in message
    news:%...
    > Suppose I have a hyperlink that, when clicked, executes a JavaScript
    > function on the client. Separately I have a button that, when clicked,
    > causes a post back and executes a server-side function, as in the

    following:
    >
    > <a id="HyperLink5" href="javascript:DoSomethingInClient()">Do

    Something</a>
    >
    > <asp:Button id="btnSaveChanges" EnableViewState="true"
    > CommandName="SaveChanges" Visible="true" Width="115" runat="server"
    > Text="Save Changes"></asp:Button>
    >
    > What I want is to have it so that when the user clicks on the hyperlink,

    the
    > JavaScript function executes and then the PostBack gets initiated
    > immediately after the JavaScript function does its thing - as if the user
    > had clicked on the Save Changes button (but without requiring the user to
    > click on the button). That is, I want the JavaScript to make its

    client-side
    > changes and then cause the server-side "Save Changes" function to execute.
    > Any ideas?


    Use btnSaveChanges.click() in DoSomethingInClient.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jun 13, 2004
    #2
    1. Advertising

  3. Sorry if I'm a bit dense on this, but here is the syntax I used and it
    doesn't trigger the server-side code:

    function DoSomethingInClient() {
    Do Some Stuff Here
    btnSaveChanges.click();
    }

    How can I get the server-side code (btnSaveChanges.click()) to execute?

    Thanks.


    "John Saunders" <> wrote in message
    news:%...
    > "Guadala Harry" <> wrote in message
    > news:%...
    > > Suppose I have a hyperlink that, when clicked, executes a JavaScript
    > > function on the client. Separately I have a button that, when clicked,
    > > causes a post back and executes a server-side function, as in the

    > following:
    > >
    > > <a id="HyperLink5" href="javascript:DoSomethingInClient()">Do

    > Something</a>
    > >
    > > <asp:Button id="btnSaveChanges" EnableViewState="true"
    > > CommandName="SaveChanges" Visible="true" Width="115" runat="server"
    > > Text="Save Changes"></asp:Button>
    > >
    > > What I want is to have it so that when the user clicks on the hyperlink,

    > the
    > > JavaScript function executes and then the PostBack gets initiated
    > > immediately after the JavaScript function does its thing - as if the

    user
    > > had clicked on the Save Changes button (but without requiring the user

    to
    > > click on the button). That is, I want the JavaScript to make its

    > client-side
    > > changes and then cause the server-side "Save Changes" function to

    execute.
    > > Any ideas?

    >
    > Use btnSaveChanges.click() in DoSomethingInClient.
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
     
    Guadala Harry, Jun 13, 2004
    #3
  4. "Guadala Harry" <> wrote in message
    news:...
    > Sorry if I'm a bit dense on this, but here is the syntax I used and it
    > doesn't trigger the server-side code:
    >
    > function DoSomethingInClient() {
    > Do Some Stuff Here
    > btnSaveChanges.click();
    > }
    >
    > How can I get the server-side code (btnSaveChanges.click()) to execute?


    I'm surprised that didn't work.

    In server code, you can call GetPostBackClientEvent(btnSaveChanges) to get a
    string containing a JavaScript function which can be called to do a
    postback. I'll research this a bit and get you back some code.
    --
    John Saunders
    johnwsaundersiii at hotmail


    > "John Saunders" <> wrote in message
    > news:%...
    > > "Guadala Harry" <> wrote in message
    > > news:%...
    > > > Suppose I have a hyperlink that, when clicked, executes a JavaScript
    > > > function on the client. Separately I have a button that, when clicked,
    > > > causes a post back and executes a server-side function, as in the

    > > following:
    > > >
    > > > <a id="HyperLink5" href="javascript:DoSomethingInClient()">Do

    > > Something</a>
    > > >
    > > > <asp:Button id="btnSaveChanges" EnableViewState="true"
    > > > CommandName="SaveChanges" Visible="true" Width="115" runat="server"
    > > > Text="Save Changes"></asp:Button>
    > > >
    > > > What I want is to have it so that when the user clicks on the

    hyperlink,
    > > the
    > > > JavaScript function executes and then the PostBack gets initiated
    > > > immediately after the JavaScript function does its thing - as if the

    > user
    > > > had clicked on the Save Changes button (but without requiring the user

    > to
    > > > click on the button). That is, I want the JavaScript to make its

    > > client-side
    > > > changes and then cause the server-side "Save Changes" function to

    > execute.
    > > > Any ideas?

    > >
    > > Use btnSaveChanges.click() in DoSomethingInClient.
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >

    >
    >
     
    John Saunders, Jun 14, 2004
    #4
  5. Re: Run Server-side Function *immediately after* executing client

    Hi
    You can call Server Side Script from Client Script Execution.
    function DoSomethingInClient()
    {
    Do Some Stuff Here
    __doPostBack('btnSaveClick','');
    }
    I am using same code and its working for me....








    "John Saunders" wrote:

    > "Guadala Harry" <> wrote in message
    > news:...
    > > Sorry if I'm a bit dense on this, but here is the syntax I used and it
    > > doesn't trigger the server-side code:
    > >
    > > function DoSomethingInClient() {
    > > Do Some Stuff Here
    > > btnSaveChanges.click();
    > > }
    > >
    > > How can I get the server-side code (btnSaveChanges.click()) to execute?

    >
    > I'm surprised that didn't work.
    >
    > In server code, you can call GetPostBackClientEvent(btnSaveChanges) to get a
    > string containing a JavaScript function which can be called to do a
    > postback. I'll research this a bit and get you back some code.
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    > > "John Saunders" <> wrote in message
    > > news:%...
    > > > "Guadala Harry" <> wrote in message
    > > > news:%...
    > > > > Suppose I have a hyperlink that, when clicked, executes a JavaScript
    > > > > function on the client. Separately I have a button that, when clicked,
    > > > > causes a post back and executes a server-side function, as in the
    > > > following:
    > > > >
    > > > > <a id="HyperLink5" href="javascript:DoSomethingInClient()">Do
    > > > Something</a>
    > > > >
    > > > > <asp:Button id="btnSaveChanges" EnableViewState="true"
    > > > > CommandName="SaveChanges" Visible="true" Width="115" runat="server"
    > > > > Text="Save Changes"></asp:Button>
    > > > >
    > > > > What I want is to have it so that when the user clicks on the

    > hyperlink,
    > > > the
    > > > > JavaScript function executes and then the PostBack gets initiated
    > > > > immediately after the JavaScript function does its thing - as if the

    > > user
    > > > > had clicked on the Save Changes button (but without requiring the user

    > > to
    > > > > click on the button). That is, I want the JavaScript to make its
    > > > client-side
    > > > > changes and then cause the server-side "Save Changes" function to

    > > execute.
    > > > > Any ideas?
    > > >
    > > > Use btnSaveChanges.click() in DoSomethingInClient.
    > > > --
    > > > John Saunders
    > > > johnwsaundersiii at hotmail
    > > >
    > > >

    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?aGFyaSBwcmFzYWQ=?=, Jun 15, 2004
    #5
    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. aa
    Replies:
    1
    Views:
    350
    Joaquin Corchero
    Mar 8, 2005
  2. =?Utf-8?B?bGFuZW0=?=
    Replies:
    3
    Views:
    29,361
    Eliyahu Goldin
    Mar 30, 2005
  3. Boss302
    Replies:
    0
    Views:
    1,102
    Boss302
    Nov 21, 2006
  4. Fernando Perez
    Replies:
    5
    Views:
    131
    Fernando Perez
    Aug 1, 2010
  5. Replies:
    2
    Views:
    293
Loading...

Share This Page