ASP.NET Questions

Discussion in 'ASP .Net' started by Tony, Apr 26, 2005.

  1. Tony

    Tony Guest

    Hi,

    I hope I can find answers to my questions here.

    1. How to execute a Private Sub in VB, from a Javascript function event.
    2. How to get a JavaScript Var value from the html page and return to the VB
    Codebehind.
    3. If there is a way to execute a JavaScript function before the VB Code
    behind page_load event.

    Waiting anxiously for your favourable reply.

    TIA

    Tony
     
    Tony, Apr 26, 2005
    #1
    1. Advertising

  2. "Tony" <> ¦b¶l¥ó
    news:% ¤¤¼¶¼g...
    > Hi,
    >
    > I hope I can find answers to my questions here.
    >
    > 1. How to execute a Private Sub in VB, from a Javascript function event.

    1) Use javascript to link event to a button, then call the Sub from that
    event handler(can be added by "AddHandler" statement); or
    2) make use of "__dopostback()" javascript call.
    (Both methods are too long to describe here, try Google them using keywords
    in double quotes.)

    > 2. How to get a JavaScript Var value from the html page and return to the

    VB
    > Codebehind.

    On the onclick property of submit button, put something like onclick="return
    addValue()".
    Then define a function like:
    function addValue() {
    document.getElementById("hidden1").value = var1;
    return true;
    }
    Where "hidden1" is a server-side input hidden control, and var1 is the
    variable.

    > 3. If there is a way to execute a JavaScript function before the VB Code
    > behind page_load event.

    No. There's only one round-trip - client to server, then back to client when
    finished.

    > Waiting anxiously for your favourable reply.
    >
    > TIA
    >
    > Tony
    >
    >
     
    Lau Lei Cheong, Apr 26, 2005
    #2
    1. Advertising

  3. Hi Tony,

    Let me give you the principles, and you should be able to solve any
    client-side/server-side problem from those.

    The client and the server are disconnected. HTTP is stateless. IOW, HTTP is
    simply a Request/Response messaging protocol. Every Request is sent isolated
    from any other Request, and every Response is sent isolated from any other
    Response. In essence, you have a series of Request/Response pairs that are
    isolated from each other.

    So, how does the client send data to the server, and how does the server
    send data to the client? The answer should be obvous: The only way to pass
    data from the client is via a Request. The only way to pass data from the
    server to the client is via a Response. This is why ASP.Net uses the
    PostBack model to handle client-side events on the server. The PostBack is a
    way of the client "reminding" the server of what the status of the last Page
    instance WAS.

    More specifically, you have JavaScript functions on the client which can
    interact with the client browser and the HTML document in the browser. So,
    how does a JavaScript function pass data to the server? It adds the data to
    the form, which is POSTed to the server via PostBack or simple form POST.

    Now to your questions, in light of the principles I have outlined (hopefully
    this should appear obvious at this point):

    > 1. How to execute a Private Sub in VB, from a Javascript function event.


    The JavaScript function adds data to the form, which is POSTed to the
    server. The server Page class handles the Request. It looks for the data
    that the JavaScript function has passed, and deals with it if it is present,
    according to the data, and how the class is designed to handle such data.
    BTW, in essence, this is how PostBacks work. A client-side HTML form element
    (which represents a server-side Control) passes a value to the client-side
    JavaScript _doPostBack() function, which adds the value to a hidden form
    field, and then Posts the data (with all the form data) to the server. On
    the server, an event handler method receives the data from the _doPostBack()
    function during the LoadPostData event.

    > 2. How to get a JavaScript Var value from the html page and return to the
    > VB Codebehind.


    A JavaScript function adds the variable value to the form, which is POSTed
    to the server.

    > 3. If there is a way to execute a JavaScript function before the VB Code
    > behind page_load event.


    Well, that one is a little tricky to explain. It is possible, but you have
    to understand that in the lifetime of a Page, there can be many PostBacks.
    Technically, as HTTP is stateless, we are not talking about the lifetime of
    A Page, but the lifetimes of many instances of a Page. Obviously, if the
    page was initially called via a URL or Response.Redirect, there would be no
    JavaScript present on the client to execute. Once the Page is loaded, the
    JavaScript could be part of the Page, and do what we've already discussed,
    adding data to the next Request. In that case, there are 3 different events
    in the Page class that occur before Load (Init, LoadViewState,
    LoadPostData). So, in that case only, yes, the JavaScript function would
    happen (in time) before the Page_Load event, and the data from the function
    could be handled prior to the Page_Load event.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    What You Seek Is What You Get.


    "Tony" <> wrote in message
    news:%...
    > Hi,
    >
    > I hope I can find answers to my questions here.
    >
    > 1. How to execute a Private Sub in VB, from a Javascript function event.
    > 2. How to get a JavaScript Var value from the html page and return to the
    > VB Codebehind.
    > 3. If there is a way to execute a JavaScript function before the VB Code
    > behind page_load event.
    >
    > Waiting anxiously for your favourable reply.
    >
    > TIA
    >
    > Tony
    >
     
    Kevin Spencer, Apr 26, 2005
    #3
  4. Tony

    Tony Guest

    Thanks Kevin and Lau,
    I really appriciate your help, I am really thankfull to you for that.
    I learned a lot from your postings.

    Keep it up you really are great peoples.

    Thanks

    Tony


    "Kevin Spencer" <> wrote in message
    news:...
    > Hi Tony,
    >
    > Let me give you the principles, and you should be able to solve any
    > client-side/server-side problem from those.
    >
    > The client and the server are disconnected. HTTP is stateless. IOW, HTTP
    > is simply a Request/Response messaging protocol. Every Request is sent
    > isolated from any other Request, and every Response is sent isolated from
    > any other Response. In essence, you have a series of Request/Response
    > pairs that are isolated from each other.
    >
    > So, how does the client send data to the server, and how does the server
    > send data to the client? The answer should be obvous: The only way to pass
    > data from the client is via a Request. The only way to pass data from the
    > server to the client is via a Response. This is why ASP.Net uses the
    > PostBack model to handle client-side events on the server. The PostBack is
    > a way of the client "reminding" the server of what the status of the last
    > Page instance WAS.
    >
    > More specifically, you have JavaScript functions on the client which can
    > interact with the client browser and the HTML document in the browser. So,
    > how does a JavaScript function pass data to the server? It adds the data
    > to the form, which is POSTed to the server via PostBack or simple form
    > POST.
    >
    > Now to your questions, in light of the principles I have outlined
    > (hopefully this should appear obvious at this point):
    >
    >> 1. How to execute a Private Sub in VB, from a Javascript function event.

    >
    > The JavaScript function adds data to the form, which is POSTed to the
    > server. The server Page class handles the Request. It looks for the data
    > that the JavaScript function has passed, and deals with it if it is
    > present, according to the data, and how the class is designed to handle
    > such data. BTW, in essence, this is how PostBacks work. A client-side HTML
    > form element (which represents a server-side Control) passes a value to
    > the client-side JavaScript _doPostBack() function, which adds the value to
    > a hidden form field, and then Posts the data (with all the form data) to
    > the server. On the server, an event handler method receives the data from
    > the _doPostBack() function during the LoadPostData event.
    >
    >> 2. How to get a JavaScript Var value from the html page and return to the
    >> VB Codebehind.

    >
    > A JavaScript function adds the variable value to the form, which is POSTed
    > to the server.
    >
    >> 3. If there is a way to execute a JavaScript function before the VB Code
    >> behind page_load event.

    >
    > Well, that one is a little tricky to explain. It is possible, but you have
    > to understand that in the lifetime of a Page, there can be many PostBacks.
    > Technically, as HTTP is stateless, we are not talking about the lifetime
    > of A Page, but the lifetimes of many instances of a Page. Obviously, if
    > the page was initially called via a URL or Response.Redirect, there would
    > be no JavaScript present on the client to execute. Once the Page is
    > loaded, the JavaScript could be part of the Page, and do what we've
    > already discussed, adding data to the next Request. In that case, there
    > are 3 different events in the Page class that occur before Load (Init,
    > LoadViewState, LoadPostData). So, in that case only, yes, the JavaScript
    > function would happen (in time) before the Page_Load event, and the data
    > from the function could be handled prior to the Page_Load event.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > What You Seek Is What You Get.
    >
    >
    > "Tony" <> wrote in message
    > news:%...
    >> Hi,
    >>
    >> I hope I can find answers to my questions here.
    >>
    >> 1. How to execute a Private Sub in VB, from a Javascript function event.
    >> 2. How to get a JavaScript Var value from the html page and return to the
    >> VB Codebehind.
    >> 3. If there is a way to execute a JavaScript function before the VB Code
    >> behind page_load event.
    >>
    >> Waiting anxiously for your favourable reply.
    >>
    >> TIA
    >>
    >> Tony
    >>

    >
    >
     
    Tony, Apr 26, 2005
    #4
    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. Ali Syed
    Replies:
    3
    Views:
    561
    Mark McIntyre
    Oct 13, 2004
  2. pkirk25
    Replies:
    50
    Views:
    1,120
    Bill Pursell
    Oct 4, 2006
  3. Replies:
    10
    Views:
    555
  4. Vijay
    Replies:
    2
    Views:
    594
    Öö Tiib
    May 7, 2010
  5. reema
    Replies:
    0
    Views:
    281
    reema
    Aug 26, 2008
Loading...

Share This Page