JavaScript: call C# codebehind function

DeveloperDevine

Hi i wanted to know is it possible to call a codebehind function in my Javascript? The javascript is in the head of my asp.net webpage page.

I have tried many methods but none seem to have worked. Its the first time iv had to do this so an example would be a nice learning curve fix.

My codebehind function in C#

protected void GetAverageRent_TextChanged(object sender, EventArgs e)
{
    string Postcode = _postCodeInput.Value.ToString();
    var webGet = new HtmlWeb();
    var doc = webGet.Load("http://www.webadress.com/" + Postcode);


    HtmlNode AvgPrice = doc.DocumentNode.SelectSingleNode("//div[@class='split2r right']//strong[@class='price big']");

    if (AvgPrice != null)
    {
        AverageRentLbl.Text = AvgPrice.InnerHtml.ToString();
    }
    else
    {
        AverageRentLbl.Text = "Invalid Postcode!";
        AverageRentLbl.ForeColor = Color.Red;
        AverageRentLbl.Font.Bold = true;
    }
}

My Javascript

<script>
function codeAddress() {

        document.getElementById('map-canvas').setAttribute("style", "height:200px");

        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var mapOptions = {
            zoom: 16,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        //var address = document.getElementById('_mainContentHolder__postCodeValue').value;
        var address = document.getElementById('ContentPlaceHolder1__postCodeInput').value;

        geocoder.geocode({ 'address': address }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });

                document.getElementById('ContentPlaceHolder1__latValue').value = results[0].geometry.location.lat();
                document.getElementById('ContentPlaceHolder1__longValue').value = results[0].geometry.location.lng();
            } else {
                alert('Sorry the postcode you entered in invalid. Please try again: ' + status);
                document.getElementById('ContentPlaceHolder1__postCodeInput').value = "";
            }
        });</Script>
Shashank Chaturvedi

W3Schools have a complete tutorial (http://www.w3schools.com/ajax/default.asp) on Ajax. AJAX is asynchronous javascript and XML, so its pretty obvious javascript can make it happen. If you want just your text change event to fire asynchronously, then I would suggest you to use Update panel, that will save you a lot of trouble.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to call a codebehind function using javascript?

From Dev

Call codebehind function in jquery

From Dev

Call codebehind function in jquery

From Dev

Call Javascript function from codebehind using vb.net

From Dev

How to call a codebehind function from javascript in asp.net?

From Dev

call javascript method from codebehind

From Dev

I Want to call multiple javascript function from codebehind on button click. it works fine for 3 javascript function but not more than that

From Dev

How to add a JavaScript function to an HmlGenericControl from codebehind

From Dev

Pass Javascript Array of Objects to C# Codebehind

From Dev

Calling server-side C# function from either javascript or codebehind c# function ASP.NET

From Dev

Javascript function returns error when I click on a <li> on codebehind

From Dev

Calling JavaScript Function From CodeBehind fails to fill getElementbyID

From Dev

JavaScript code calling codebehind function only one time

From Dev

Calling jQuery function using C# CodeBehind with return value

From Dev

Calling jQuery function using C# CodeBehind with return value

From Dev

Call C++ function pointer from Javascript

From Dev

Call javascript function in c# actionlink

From Dev

How to call a C# function from JavaScript?

From Dev

Can't get Javascript to fire from c# codebehind

From Dev

using a codebehind function with eval

From Dev

How to call mfc C++ function in HTML JavaScript and how to call JavaScript Function in mfc C++?

From Java

Call a CodeBehind Method from ViewModel

From Dev

Call javascript function with if JSTL

From Dev

Javascript function call in Handlebar

From Java

Vulnerable JavaScript function call

From Dev

JavaScript - conditionally call a function

From Dev

JavaScript call() function

From Dev

Output of call function in javascript

From Dev

Javascript Function Instance and call

Related Related

  1. 1

    How to call a codebehind function using javascript?

  2. 2

    Call codebehind function in jquery

  3. 3

    Call codebehind function in jquery

  4. 4

    Call Javascript function from codebehind using vb.net

  5. 5

    How to call a codebehind function from javascript in asp.net?

  6. 6

    call javascript method from codebehind

  7. 7

    I Want to call multiple javascript function from codebehind on button click. it works fine for 3 javascript function but not more than that

  8. 8

    How to add a JavaScript function to an HmlGenericControl from codebehind

  9. 9

    Pass Javascript Array of Objects to C# Codebehind

  10. 10

    Calling server-side C# function from either javascript or codebehind c# function ASP.NET

  11. 11

    Javascript function returns error when I click on a <li> on codebehind

  12. 12

    Calling JavaScript Function From CodeBehind fails to fill getElementbyID

  13. 13

    JavaScript code calling codebehind function only one time

  14. 14

    Calling jQuery function using C# CodeBehind with return value

  15. 15

    Calling jQuery function using C# CodeBehind with return value

  16. 16

    Call C++ function pointer from Javascript

  17. 17

    Call javascript function in c# actionlink

  18. 18

    How to call a C# function from JavaScript?

  19. 19

    Can't get Javascript to fire from c# codebehind

  20. 20

    using a codebehind function with eval

  21. 21

    How to call mfc C++ function in HTML JavaScript and how to call JavaScript Function in mfc C++?

  22. 22

    Call a CodeBehind Method from ViewModel

  23. 23

    Call javascript function with if JSTL

  24. 24

    Javascript function call in Handlebar

  25. 25

    Vulnerable JavaScript function call

  26. 26

    JavaScript - conditionally call a function

  27. 27

    JavaScript call() function

  28. 28

    Output of call function in javascript

  29. 29

    Javascript Function Instance and call

HotTag

Archive