How to call a codebehind method from clientside javascript

Discussion in 'ASP .Net' started by =?Utf-8?B?Um9iIFNob3JuZXk=?=, Nov 3, 2004.

  1. Hi,

    I am using .Net 2003 , c# asp.net.
    The situation i have is this. I have a asp.net page which in the codebehind
    maintains an xml document in memory. The user can click on a button to popup
    a windows to select some items, this is done via window.open, I then return
    the selected items via the returnValue, when I receive the data back I need
    to be able to call into a function in my main page codebehind to update the
    xml.

    Thus my question is how can a clienttside javascript function call a
    function that resides in codebehind, I envisage that it may be something to
    with the __doPostBack function.

    In addition how do I call the control_SelectedIndexChanged() function from
    client side java script.

    --
    Regards

    Rob
    =?Utf-8?B?Um9iIFNob3JuZXk=?=, Nov 3, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?Um9iIFNob3JuZXk=?=

    Saravana Guest

    Check out this link,
    http://msdn.microsoft.com/library/d...eneratingclient-sidejavascriptforpostback.asp
    --
    Saravana
    http://dotnetjunkies.com/WebLog/saravana/
    www.ExtremeExperts.com


    "Rob Shorney" <> wrote in message
    news:...
    > Hi,
    >
    > I am using .Net 2003 , c# asp.net.
    > The situation i have is this. I have a asp.net page which in the

    codebehind
    > maintains an xml document in memory. The user can click on a button to

    popup
    > a windows to select some items, this is done via window.open, I then

    return
    > the selected items via the returnValue, when I receive the data back I

    need
    > to be able to call into a function in my main page codebehind to update

    the
    > xml.
    >
    > Thus my question is how can a clienttside javascript function call a
    > function that resides in codebehind, I envisage that it may be something

    to
    > with the __doPostBack function.
    >
    > In addition how do I call the control_SelectedIndexChanged() function from
    > client side java script.
    >
    > --
    > Regards
    >
    > Rob
    Saravana, Nov 3, 2004
    #2
    1. Advertising

  3. Rob,

    Client is a client and server is a server. They live in two different
    worlds. Client can't call any codebehind methods. What it can do is to pass
    to the server a sort of info that the server will understand as a request
    for an action involving calling a codebehind method.

    Now, your question is how to communicate an action with a few parameters
    from client to server. I don't recommend using __doPostBack etc. It is a
    sort of internal function and as such can change with another ASP.NET
    release. It is not even documented in MSDN. The standard and much simpler
    solution is to provide hidden <input> fields that you will fill on
    clientside with the action code and parameters and to read them on
    serverside.

    Eliyahu

    "Rob Shorney" <> wrote in message
    news:...
    > Hi,
    >
    > I am using .Net 2003 , c# asp.net.
    > The situation i have is this. I have a asp.net page which in the

    codebehind
    > maintains an xml document in memory. The user can click on a button to

    popup
    > a windows to select some items, this is done via window.open, I then

    return
    > the selected items via the returnValue, when I receive the data back I

    need
    > to be able to call into a function in my main page codebehind to update

    the
    > xml.
    >
    > Thus my question is how can a clienttside javascript function call a
    > function that resides in codebehind, I envisage that it may be something

    to
    > with the __doPostBack function.
    >
    > In addition how do I call the control_SelectedIndexChanged() function from
    > client side java script.
    >
    > --
    > Regards
    >
    > Rob
    Eliyahu Goldin, Nov 3, 2004
    #3
  4. Hi Rob,

    I think Eliyahu 's suggestions are reasonable. Generally if we want to
    manually post back the page so as to do some serverside works, we have the
    following means:
    1. Put some hidden fields (<input type="hidden" .>) on the page which
    used to store some flag, then we use document.forms[0].submit() to post
    back the page and in the Page_Load event we can call the correct function
    we need according to the hidden fields' value.

    2. Put an hidden Html input button on the page and use script to call the
    button's clientside "click()" method so as to post back the page. For
    example:

    <input type="button" id="btnHidden" style="display:none" runat="server"
    onserverclick"serverside_handler">

    we can use the following script to make the button clicked:

    var btn = document.getElementById("btnHidden");
    btn.click();

    "severside_handler" is the codebehind function that hander the button's
    server click event.

    Hope also helps. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Nov 4, 2004
    #4
  5. Rob,
    What you describe really sounds like Remote Scripting (now inaccurately
    dubbed "AJAX") , which would be done with XmlHttpRequest. ASP.NET 2.0 has
    some of this functionality with Client Script Callbacks.
    Peter

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




    "Rob Shorney" wrote:

    > Hi,
    >
    > I am using .Net 2003 , c# asp.net.
    > The situation i have is this. I have a asp.net page which in the codebehind
    > maintains an xml document in memory. The user can click on a button to popup
    > a windows to select some items, this is done via window.open, I then return
    > the selected items via the returnValue, when I receive the data back I need
    > to be able to call into a function in my main page codebehind to update the
    > xml.
    >
    > Thus my question is how can a clienttside javascript function call a
    > function that resides in codebehind, I envisage that it may be something to
    > with the __doPostBack function.
    >
    > In addition how do I call the control_SelectedIndexChanged() function from
    > client side java script.
    >
    > --
    > Regards
    >
    > Rob
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Feb 16, 2006
    #5
  6. =?Utf-8?B?Um9iIFNob3JuZXk=?=

    sjr.priyanka

    Joined:
    Oct 8, 2011
    Messages:
    4
    sjr.priyanka, Oct 8, 2011
    #6
  7. =?Utf-8?B?Um9iIFNob3JuZXk=?=

    rakhy_rakey

    Joined:
    Jun 17, 2010
    Messages:
    2
    thanks. It helped me

    thanks. It helped me

    rakhy_rakey, Nov 16, 2011
    #7
    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. fxs
    Replies:
    4
    Views:
    6,280
  2. IkBenHet
    Replies:
    1
    Views:
    1,440
    Peter Blum
    Aug 10, 2005
  3. Tom
    Replies:
    1
    Views:
    437
  4. JB
    Replies:
    0
    Views:
    2,215
  5. dany
    Replies:
    1
    Views:
    180
Loading...

Share This Page