Hi all,
Can anybody please tell me how to call a javascript function from a vb.net,
If its possible then please give a sample code.
thanks in advance.
Hi all,
Can anybody please tell me how to call a javascript function from a vb.net,
If its possible then please give a sample code.
thanks in advance.
You could try this,
Code:Response.Write ("call javascript, eg alert('test 123');"
I will not recommend using Response.Write for writing javascript. Although it is not some invalid way but not the standard way. Secondly it will write the javascript before the actual <HTML> tag begin that at the top of the page. So if during page rendering the javascript code that you have written using response.write calls a javascript method that is written else where e.g., at the bottom of the page, it will generate an error because the browser have not rendered it yet.
You can use Page.RegisterClientScriptBlock or Page.RegisterStartUpScript to register client script the difference between the two is that RegisterClientScriptBlock inserts javascript just before the beginning of <Form> tag while RegisterStartUpScript inserts script just after </FORM? tag.
So accroding to your situation you can modify your code as follows
Page.RegisterClientScriptBlock("SCRIPTNAME","<script language='javascript'>compute();</script>")
Or
Page.RegisterStartUpScript("SCRIPTNAME","<script language='javascript'>compute();</script>")
This is the function at html page:
To call this javascript function from Vb.net code, Use Page.RegisterStartupScript function like the code below:Code:<script language=”javascript”> function test() { //Add the function code here } </script>
Code:Dim strScript As String = “<script language=javascript” id=’myClientScript’>test();</script>” Page.RegisterStartupScript(“callTest”,strScript)
For some more information about this thread,
you can click here..
Bookmarks