calling asp.net code behind function from window.onload javascript function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akg
    New Member
    • Jan 2007
    • 19

    calling asp.net code behind function from window.onload javascript function

    Hi Gurus,

    I have a requirement like below. In my asp.net(C#) code behind file "MyPage.aspx.cs " file I have a function like below:

    void PopulateAccount (int AccountNumber)
    {
    this.AccountNum ber.Text = AccountNumber;
    }

    I want to call this function from JavaScript (inside the window.onload function) from my MyPage.aspx page, something like below:

    window.onload = function()
    {
    // I need to call my PopulateAccount method inside this function so that it can populate the AccountNumber Text Box
    }

    is this possible ?. Please help me how to do this . I am using ASP.Net 1.1 with C#.



    Thanks and Regards,
    Amit
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can call server-side code on the client side using AJAX. See the AJAX links in the Offsite Links thread.

    Comment

    • akg
      New Member
      • Jan 2007
      • 19

      #3
      Originally posted by acoder
      You can call server-side code on the client side using AJAX. See the AJAX links in the Offsite Links thread.
      acoder,
      you have posted following links here. could you please tell me which one i should refer for my problem.

      AJAX:Getting Started (Mozilla Developer Center)
      http://www.xul.fr/en-xml-ajax.html (GET, POST, text and XML examples)
      Jibbering
      W3Schools AJAX Tutorial
      Captain's AJAX Form Post/Get

      Thanks,
      Amit

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Those are tutorial links. Read through them and try them out. They should help you understand ajax. For your problem, create a server-side (C#) file which outputs the result of the function. Then make a request using XMLHttp calling that file with the correct parameters.

        One other alternative is to use ASP.NET AJAX.

        If you have problems, post your code here.

        Comment

        Working...