Solved

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

Posted on 2011-02-20
4
251 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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, …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now