Is it possible to call a VB.NET function in javascript?

Rate It (1)

Last post 05-09-2008 8:04 AM by Suprotim Agarwal. 6 replies.

Sort Posts:

  • Is it possible to call a VB.NET function in javascript?

    05-07-2008, 9:01 AM
    • Loading...
    • pimps
    • Joined on 03-03-2008, 1:20 PM
    • Posts 95

    Hi,

    In this code I show an alert. But instead of the alert it has to do a function. Since it's not possible to connect to an sql database with javascript I need to do this in a function in my VB script section.
    That function I would like to call in my javascript when my javascript function is called.

    Here is the javascript code:

    function GetKeyPress()

    {

    alert(window.event.keyCode)

    }

     

    Many thx in advance !!

  • Re: Is it possible to call a VB.NET function in javascript?

    05-07-2008, 9:14 AM

    Hi,

    I hope you meant VB.NET and not vbscript. Check a post of mine over here

    How to call Server Side function from Client Side Code using PageMethods in ASP.NET AJAX

     HTH,
    Suprotim Agarwal

     

    GridView Tips and Tricks using ASP.NET 2.0 | MSDN Forums Moderator

    Click "Mark as Answer" on the post that helped you to help future readers.
  • Re: Is it possible to call a VB.NET function in javascript?

    05-07-2008, 10:43 AM
    • Loading...
    • pimps
    • Joined on 03-03-2008, 1:20 PM
    • Posts 95

    thx for your reaction.

    I tried to accomplish it like on your post. But my situation is a bit different. In stead of the onblur I need the onkeypress function. I have a TextBoxCustomer. When the customer starts filling the textbox with a name, it has to check after every keypress if TextBoxCustomer.Text is a name in the database (tblUser) and if there is a name check that this name is unique.

    Can you help me with this?? I have followed your example exactly as you did in your post. But when I type a character in TextBoxCustomer my pages gives me javascript errors.

     

    Many thx in advance!!

  • Re: Is it possible to call a VB.NET function in javascript?

    05-07-2008, 11:20 AM
    • Loading...
    • cdpandya1
    • Joined on 05-17-2007, 9:59 AM
    • Ahmedabad
    • Posts 62

     Yes. It is possible to call the VB.NET function from javascript. Please refer following URL which should give you the solution.

    http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=668

    In the above URL, see the below line which will call the server side function from javascript.  

    window.execScript("__doPostBack('UpdateQuantity', '" + retval + "')","JavaScript");

    Chintan
    Please remember to 'Mark as Answer' if this post answered your question!
  • Re: Is it possible to call a VB.NET function in javascript?

    05-08-2008, 4:13 AM
    • Loading...
    • pimps
    • Joined on 03-03-2008, 1:20 PM
    • Posts 95

    thx for the reaction but my function is still not working. I don't understand your code cdpandya1. My function has to check a checkbox. When I keypress, for example 'a', it has to check the database on the names. If there is a name called 'a' and this name is unique. It has to fill my textbox.

    Another example:

    these names are in my database:

    HANNESST
    HANNOFF
    HANNOHH

    So when somebody is typing text in the text box and he types HANNE, my function should fill my textbox with the name HANNESST because this name is unique at that moment.

    Does somebody have an idea how to solve this or can somebody provide me some code??

    Many thx in advance!!

  • Re: Is it possible to call a VB.NET function in javascript?

    05-08-2008, 10:20 PM
    Answer

    Hi,

    Two approaches are available.

    1. In Code Behind, please declare the VB.Net Function as the Public function.

       At JavaScript, you can use <%=VBFunction();%> to call the function which is in Code Behind.

    2. Do post back by using JavaScript function to call VB.Net function.

        On this way, please check this thread: http://forums.asp.net/t/1227950.aspx

        In your scenario, you need to call __doPostBack function in GetKeyPress() function. In Page_Load, it will call VBFunction after checking the parameters of post back.

    Hope it helps.

     

    ================================================
    Sincerely,
    Vince Xu
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question. This can be beneficial to other
    community members reading the thread.
  • Re: Is it possible to call a VB.NET function in javascript?

    05-09-2008, 8:04 AM
    Answer

    In stead of the onblur I need the onkeypress function. I have a TextBoxCustomer. When the customer starts filling the textbox with a name, it has to check after every keypress if TextBoxCustomer.Text is a name in the database (tblUser) and if there is a name check that this name is unique.

    Are you sure you want to do that? That won't be an optimum solution at all. Imagine the db getting hit that many times. I feel the best way to handle this would be either on the submit button click or on the blur.

    HTH,
    Suprotim Agarwal 

     

    GridView Tips and Tricks using ASP.NET 2.0 | MSDN Forums Moderator

    Click "Mark as Answer" on the post that helped you to help future readers.
Page 1 of 1 (7 items)