Results 1 to 5 of 5

Thread: Call Javascript function in VB.Net code

  1. #1
    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.

  2. #2
    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');"

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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>")

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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)

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Adding JavaScript to a Server Control

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

Similar Threads

  1. using href vs. onclick to call javascript function
    By Kalyug in forum Software Development
    Replies: 6
    Last Post: 12-05-2010, 10:09 AM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Javascript isNull function
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 11-11-2009, 02:51 PM
  4. How to call Readonly textbox in Javascript Function
    By Aldous in forum Windows Software
    Replies: 3
    Last Post: 12-08-2009, 11:39 AM
  5. JavaScript function help
    By suseman in forum Software Development
    Replies: 3
    Last Post: 26-05-2009, 05:11 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,271,645.23254 seconds with 17 queries