Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 22-01-2009
Member
 
Join Date: Dec 2008
Posts: 19
Call Javascript function in VB.Net code

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.
Reply With Quote
  #2  
Old 22-01-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Call Javascript function in VB.Net code

You could try this,

Code:
Response.Write ("call javascript, eg  alert('test 123');"
Reply With Quote
  #3  
Old 22-01-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Call Javascript function in VB.Net code

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>")
Reply With Quote
  #4  
Old 22-01-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Call Javascript function in VB.Net code

This is the function at html page:

Code:
<script language=?javascript?>
   function test()
   {
      //Add the function code here
   }
</script>
To call this javascript function from Vb.net code, Use Page.RegisterStartupScript function like the code below:

Code:
Dim strScript As String = ?<script language=javascript? id=?myClientScript?>test();</script>?
Page.RegisterStartupScript(?callTest?,strScript)
Reply With Quote
  #5  
Old 22-01-2009
Member
 
Join Date: May 2008
Posts: 2,293
Adding JavaScript to a Server Control

For some more information about this thread,
you can click here..
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Call Javascript function in VB.Net code"
Thread Thread Starter Forum Replies Last Post
using href vs. onclick to call javascript function Kalyug Software Development 6 12-05-2010 10:09 AM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
Javascript isNull function Chrisch Software Development 3 11-11-2009 02:51 PM
How to call Readonly textbox in Javascript Function Aldous Windows Software 3 12-08-2009 11:39 AM
JavaScript function help suseman Software Development 3 26-05-2009 05:11 AM


All times are GMT +5.5. The time now is 05:51 PM.