Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

using jquery ajax with onblur event but not working

$
0
0

I am having two asp textboxes, TextBoxPicPostCode and TextBoxPicAddress. The goal of this task is that when i enter a post code inTextBoxPicPostCode and the focus gets lost from this textbox it should automatically populateTextBoxPicAddress using the method in code behind(.cs code). The methodgetadd() in .cs code works fine and uses google api but i am not getting an idea how to use jquery ajax with it.

.cs code:

public void getadd()
    {
        string address = "";
        //_Address.InnerText = _PostCode.Text;
        XmlDocument xDoc = new XmlDocument();
        xDoc.Load("http://maps.google.com/maps/api/geocode/xml?address=" + TextBoxPicPostCode.Text + "&sensor=false");
        XmlNodeList distanceX = xDoc.GetElementsByTagName("formatted_address");
        if (distanceX.Count > 0)
        {
            address = distanceX[0].InnerXml;
            TextBoxPicAddress.Text = address;
        }
    }
<div class="vote"></div> <div> <div class="post-text" itemprop="text">

I am having two asp textboxes, TextBoxPicPostCode and TextBoxPicAddress. The goal of this task is that when i enter a post code inTextBoxPicPostCode and the focus gets lost from this textbox it should automatically populateTextBoxPicAddress using the method in code behind(.cs code). The methodgetadd() in .cs code works fine and uses google api but i am not getting an idea how to use jquery ajax with it.

.cs code:

public void getadd()
    {
        string address = "";
        //_Address.InnerText = _PostCode.Text;
        XmlDocument xDoc = new XmlDocument();
        xDoc.Load("http://maps.google.com/maps/api/geocode/xml?address=" + TextBoxPicPostCode.Text + "&sensor=false");
        XmlNodeList distanceX = xDoc.GetElementsByTagName("formatted_address");
        if (distanceX.Count > 0)
        {
            address = distanceX[0].InnerXml;
            TextBoxPicAddress.Text = address;
        }
    }

.aspx code which i have tried so far and it does not work:

<script type="text/javascript">

                            function submit()
                            {
                                $.ajax({
                                    type: "POST",
                                    url: "Establishment_Controller.aspx.cs/getadd",
                                    data: dataValue,
                                    contentType: 'application/json; charset=utf-8',
                                    dataType: 'json',

                                    success: function (result) {
                                        alert("We returned: " + result.d);
                                    }
                                });
                            }

                        </script><asp:TextBox ID="TextBoxPicPostCode" onblur="submit();" CssClass="time" runat="server"></asp:TextBox><asp:TextBox ID="TextBoxPicAddress"  CssClass="address" runat="server"></asp:TextBox>

</div></div>

Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>