Call VB Code Behind Function from JavaScript???

Discussion in 'ASP .Net' started by jason.gyetko@epower-inc.com, Jun 29, 2006.

  1. Guest

    I'm using JavaScript to capture a keypress in my web form. Right now
    all it does is post an alert message box. Is there a way to have it
    call a function in my VB code behind? All I really want to do is open
    another web form when a certain key is pressed. I guess I'd also like
    to be able to give focus to a specific textbox on the page when a key
    is pressed.

    In case you're wondering why... I am scanning in most of my values and
    each barcode is prefixed according to the field it goes in, so when
    "a123" is scanned, it will get put into a certain field no matter where
    the cursor is on the page, and when "b123" is scanned, that will get
    put into a certain field and so on.

    Any suggestions would be appreciated. Thanks.
    , Jun 29, 2006
    #1
    1. Advertising

  2. U can use a work around with

    document.forms(0).submit() in javascript

    That will do a PostBack server-side

    for branching, you can use a hidden

    document.forms(0).hidField.value="ScanIsOk"

    and server side

    if request.form("hidField")="ScanIsOk" then....





    wrote:
    > I'm using JavaScript to capture a keypress in my web form. Right now
    > all it does is post an alert message box. Is there a way to have it
    > call a function in my VB code behind? All I really want to do is open
    > another web form when a certain key is pressed. I guess I'd also like
    > to be able to give focus to a specific textbox on the page when a key
    > is pressed.
    >
    > In case you're wondering why... I am scanning in most of my values and
    > each barcode is prefixed according to the field it goes in, so when
    > "a123" is scanned, it will get put into a certain field no matter where
    > the cursor is on the page, and when "b123" is scanned, that will get
    > put into a certain field and so on.
    >
    > Any suggestions would be appreciated. Thanks.
    DavidTurcotte, Jun 29, 2006
    #2
    1. Advertising

  3. If you want to actually make calls to Codebehind methods in your page via
    client-side events, you need to either use Atlas (ASP.NET 2.0) or look into
    Remote Scripting ("AJAX") libraries such as Anthem.NET, which is available on
    sourceforge.net.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "" wrote:

    > I'm using JavaScript to capture a keypress in my web form. Right now
    > all it does is post an alert message box. Is there a way to have it
    > call a function in my VB code behind? All I really want to do is open
    > another web form when a certain key is pressed. I guess I'd also like
    > to be able to give focus to a specific textbox on the page when a key
    > is pressed.
    >
    > In case you're wondering why... I am scanning in most of my values and
    > each barcode is prefixed according to the field it goes in, so when
    > "a123" is scanned, it will get put into a certain field no matter where
    > the cursor is on the page, and when "b123" is scanned, that will get
    > put into a certain field and so on.
    >
    > Any suggestions would be appreciated. Thanks.
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jun 29, 2006
    #3
  4. John Prado Guest

    The best approach is Ajax to access your codebehind in JavaScript:

    See the atlas project page:

    http://atlas.asp.net


    wrote:
    > I'm using JavaScript to capture a keypress in my web form. Right now
    > all it does is post an alert message box. Is there a way to have it
    > call a function in my VB code behind? All I really want to do is open
    > another web form when a certain key is pressed. I guess I'd also like
    > to be able to give focus to a specific textbox on the page when a key
    > is pressed.
    >
    > In case you're wondering why... I am scanning in most of my values and
    > each barcode is prefixed according to the field it goes in, so when
    > "a123" is scanned, it will get put into a certain field no matter where
    > the cursor is on the page, and when "b123" is scanned, that will get
    > put into a certain field and so on.
    >
    > Any suggestions would be appreciated. Thanks.
    >
    John Prado, Jun 29, 2006
    #4
  5. this should all be easily done with client script, no need to bother the
    server.

    -- bruce (sqlwork.com)


    <> wrote in message
    news:...
    > I'm using JavaScript to capture a keypress in my web form. Right now
    > all it does is post an alert message box. Is there a way to have it
    > call a function in my VB code behind? All I really want to do is open
    > another web form when a certain key is pressed. I guess I'd also like
    > to be able to give focus to a specific textbox on the page when a key
    > is pressed.
    >
    > In case you're wondering why... I am scanning in most of my values and
    > each barcode is prefixed according to the field it goes in, so when
    > "a123" is scanned, it will get put into a certain field no matter where
    > the cursor is on the page, and when "b123" is scanned, that will get
    > put into a certain field and so on.
    >
    > Any suggestions would be appreciated. Thanks.
    >
    bruce barker \(sqlwork.com\), Jun 30, 2006
    #5
  6. Guest

    Got it. Thanks for the help!!
    , Jun 30, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    578
    Alphonse Giambrone
    Jun 28, 2003
  2. Peri
    Replies:
    2
    Views:
    2,942
  3. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    477
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  4. verci
    Replies:
    4
    Views:
    1,899
    verci
    Apr 9, 2007
  5. sajithkahawatta

    call a javascript function within code behind

    sajithkahawatta, Jun 20, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    379
    sajithkahawatta
    Jun 21, 2007
Loading...

Share This Page