Click here to Skip to main content
13,139,254 members (91,588 online)
Rate this:
Please Sign up or sign in to vote.
I have created an "usercontrol" which will accept the zip code and display state and city(returning in json format).
So I have written keyup function for zipcode textbox in javacript.
In javascript side, I want to call the webservice.
Here is my code written in the ascx page:
function OnKeyUP(s, e) {
        var len = txtZip.GetText();
            var newstring = len.replace(/[_-]/g, '');
            if (newstring.length == 5) {              
                        type: "POST",
                        url: '~/CityStateZipCodes.asmx/GetCityStateZipCodes',
                        data: "{'zip':'77853'}",
                        async: false,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                        error: function () {

But I am unable to call the webservice, can someone please help me out how to call, or give an example.
Posted 11-Feb-13 3:49am
Irbaz Haider Hashmi 11-Feb-13 10:14am
When a control is render on page the id of the html elements get changed. More information will be required in order to understand this. What error you are getting? or your javascript function is not executed at all.

Try by adding debugger; in javascript.
Try moving your code on the page rather than writing it on control.
rkuttarakabat 11-Feb-13 10:32am
The java script is executed, but its not able to call the web service, i am getting an alert as error as mentioned in the code. I have to write the code in user control as i want to use this usercontrol in many a places.
Irbaz Haider Hashmi 11-Feb-13 10:50am
try entering the complete URL of the webservice. what error are you getting? 403,404?
rkuttarakabat 11-Feb-13 10:58am
its not at all calling the the web service, if possible can u give me an example for it.
rkuttarakabat 12-Feb-13 4:32am
i am getting an error as "object XMLHttpRequest"
rkuttarakabat 12-Feb-13 10:15am
i am getting HTTP/1.1 500 Internal Server Error

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

rkuttarakabat 12-Feb-13 1:39am
this is working in normal pages, but i want in a usercontrol, and its not helping me to call the webservice.
Check this:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100