Solved

asp.net - call a javascript fumction from a public sub method in server side....

Posted on 2011-02-20
4
256 Views
Last Modified: 2012-05-11
Once a user clicks the the sumbit button that runs on the server

public sub button1_click(ByVal sender as Object, ByVal....

 ' Call a javascript function.....right here
0
Comment
Question by:GlobaLevel
  • 2
4 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34939641
Add an onClientClick attribute to the button in the aspx.

<asp:button id="button1" onClientClick="myjavascriptfunction()" ....
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34939650
an overview of the OnClientClick attribute  :

http://www.w3schools.com/aspnet/prop_webcontrol_button_onclientclick.asp
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34939675
the server can't execute javascript on the client side.
why not run the javascript when the user click the submit button ?
0
 
LVL 16

Accepted Solution

by:
BurnieP earned 500 total points
ID: 34939947
Hi,

You cannot execute a javascript directly when you are on the server, but you can tell the browser to execute a javascript function once it returns back.

You can do it using :

ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Anything", "<script type='text/javascript'>MyFunction();</script>")

Once the request goes back to the client, MyFunction() will be executed.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question