Results 1 to 6 of 6

Thread: Call a JavaScript function from VB code

  1. #1
    Join Date
    Oct 2008

    Call a JavaScript function from VB code

    How can I call a Javascript function from my VB.Net code?

    I have built a ASP.Net website in VS2005. It is one of those set-ups where you have 2 seperate files for the webpages: i.e. Default.aspx and Default.apsx.vb.

    I need to be able to call a JavaScript function from within my VB code, also I need to pass a string variable into the JavaScript function. The JavaScript code is currently sitting at the top of the Default.aspx page whereas the VB code is in the Default.apsx.vb page.

    Additional info (if it helps):

    What the VB code does is take a user-inputed address and find it in a database and returns certain info about the address. I am trying to improve it to display a Google Map of the address using the Google Maps JavaScript API.

    I already have the javascript function ready to go that takes a string address and makes and displays a google map of it, I just need to be able to call it after the user has entered their address.

  2. #2
    Join Date
    Jan 2003
    Dundee, Scotland

    you can build your javascript in your code behind then register it as a startup script.

    some example code in c#

    private void Button1_Click(object sender, System.EventArgs e)
      string javaScript =
       "<script language=JavaScript>\n" +
       "alert('Button1_Click client-side');\n" +
      RegisterStartupScript("Button1_ClickScript", javaScript); 


  3. #3
    Join Date
    Oct 2008
    Actually I have been thinking about this some more and it seems that the most sensible way to do it is to do the reverse. I.e. to pass the address to the webpage and have the javascript function pick up the address and run everytime the webpage is refreshed.

    So in other words, each time the user enters an address, that address would be stored in a hidden textbox or a cookie or something, then when the page is refreshed the javascript function grabs the address from the hidden textbox/cookie and runs it.

    But what would the JavaScript syntax be to retrieve the address from the hidden textbox or cookie? Something like "getElementbyID("Name of text box")"???

  4. #4
    Join Date
    Apr 2010
    Cocoa Beach, FL

    Simple Javascript solution to get value of element

    You can get the value of a form element completely within the Javascript scope and, then you can pass it to a URL as a URL variable which can then be processed with the ASP.NET code. That is one way to do it, probably the simplest, although there are other ways to do it also. Also a hidden form element will be processed by ASP.NET in the same way that a form element of type text is processed.

    You can access the value of a form element using getElementById, even if the form element is type HIDDEN, this is actually done quite often in web application development.

    Here is a simple example of using getElementById with a form element. It is very important that your form element has an ID attribute, or else the javascript will fail.


    <script languague="javascript">
    function ProcessForm() {
    var Address = document.getElementById("address").value;
    if (Address != "") {
    alert("Address:" + Address);
    return true;
    } else {
    return false;


    <form method="post" onsubmit="return ProcessForm();">
    Address: <input type="text" name="address" id="address" value="" />
    <input type="submit" value="Submit">


    Michael G. Workman
    Last edited by Michael_G; 07-11-2011 at 01:13 PM.

  5. #5
    Join Date
    Sep 2012
    I am attempting to do something of the same sort. My job uses a cloud based ticketing system that does not refresh an incoming ticket list on its own. I must press a specific button on the specific applet. I believe that this specific refresh button actually does two jobs; 1) any changes I make to a ticket status is updated on the server 2)grabs list of designated tickets (assigned to me and new). For example: If i change a ticket status to "Spam", click out of the field and use the designated refresh button it will remove the ticket from my view. However, if I change the ticket status to "Spam", click out of the field and do a hard refresh it ticket in question stays as originally marked and in my view.

    So my project is to create my own browser that loads the page and refresh the ticket applet every minute or two minutes and look for a new ticket. Creating the browser, timing and detect new ticket is done. However, I cannot seem to pass the javascript code for the applet from VB.

    Another issue is that since the webpage interface is not ours, I cannot modify the page to accept my own specific info. However, I have found the function on their js webpage. i am just in need of being able to pass the script and its parameters from VB.

    Here is the html code for the button:
    <a id=?"servercontentneg706_refresh" class=?"noImageUnderline portletIconRefresh" href=?"javascript:?refreshPortlet('servercontentneg706','LISTSEARCH_-706', false, '-17',null,null, null)?;?var win = window.isOLC ? window :? parent.cleanupTooltips ? parent :? window;? if (typeof win.cleanupTooltips != 'undefined')?win.cleanupTooltips('LISTSEARCH__706')?;?" onclick=?" setPortletToUpdating('servercontentneg706')?;? " title=?"Refresh">?</a>?

    Here is the code that is sent when the refresh button is clicked:
    javascript:refreshPortlet('servercontentneg706','LISTSEARCH_-706', false, '-17',null,null, null);var win = window.isOLC ? window : parent.cleanupTooltips ? parent : window; if (typeof win.cleanupTooltips != 'undefined')win.cleanupTooltips('LISTSEARCH__706');

    Here is the routine that is called (I believe):
    function refreshPortlet(f,l,e,g,m,d,h,c,k,a){setPortletToUpdating(f);var b="/app/center/setup/portletrefresher.nl?elemid="+f+"&sticky="+l;if(e!=null){b+="&noreload="+(e?"T":"F");}if(g!=null){b+= "&sc="+g;}if(m!=null){b+="&portletid="+m;}if(d!=null){b+="&entityid="+d+"&haschild="+(h?"T":"F");}if (c!=null){b+="&searchid="+c;}if(a!=null){b+="&lineid="+a;}b+="&nsts="+(new Date().getTime());if(k!=null&&k.length>0){if(k.charAt(0)=="?"){k=k.substring(1);}b+="&addparams="+es cape(k);}sendRequestToFrame(b,"server_commands");}

    I'm looking for the simplest ideas to do a refresh on the applet from my vb browser, whether it be simulating the button push (seems easiest), passing just the call to the js or even running the full routine from within VB.

    Thanks in Advance
    vb newbie

  6. #6
    Join Date
    Oct 2012
    I have a job that is responsible for filling SSRS report. The user presses the button and go out and check to see if there is data. If there is no data, I make no message data. If there is a data call SSRS report that I would like to open in a new window. I thought using the JavaScript function would be the best way to achieve this. How it's done or what you would recommend?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10158 seconds
  • Memory Usage 2,892KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates