By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Guadala Harry" <Ch*********@gh.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
Nov 18 '05 #2

P: n/a
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" <jo**************@notcoldmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Guadala Harry" <Ch*********@gh.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #3

P: n/a
"Guadala Harry" <Ch*********@gh.com> wrote in message
news:Ob*************@TK2MSFTNGP12.phx.gbl...
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" <jo**************@notcoldmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Guadala Harry" <Ch*********@gh.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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


Nov 18 '05 #4

P: n/a
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" <Ch*********@gh.com> wrote in message
news:Ob*************@TK2MSFTNGP12.phx.gbl...
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" <jo**************@notcoldmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Guadala Harry" <Ch*********@gh.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> 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



Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.