0

Sorry I could not find the appropriate title

Here is my problem

I am using a method which returns a string value like hh:mm(12:45) this method is named as DeliveryTimeCalc()

I am using a jQuery timepicker to take input on my aspx page this timepicker has to be validated by mintime the minimum time should be the value returned by the method DeliveryTimeCalc() this serverside method has to be called during the jQuery is initialized so I did the below method

<script type="text/javascript">
    $(document).ready(function () {
        //window.onload = pageMethodConcept.callServerSideMethod;
        var time = pageMethodConcept.callServerSideMethod;
        alert(time);
        var hm = time.split(':');
        var h = hm[0]; var m = hm[1];
        $("#tb_DeliveryTime").timepicker({ showPeriodLabels: false,
            onHourShow: OnHourShowCallback,
            onMinuteShow: OnMinuteShowCallback
        });
        function OnHourShowCallback(hour) {

            if ((hour < h)) {
                return false; // not valid
            }
            return true; // valid
        }
        function OnMinuteShowCallback(hour, minute) {
            if ((hour == h) && (minute <= m)) { return false; } // not valid
            return true;  // valid
        }
    });
</script>
<script language="javascript" type="text/javascript">
pageMethodConcept = {
    callServerSideMethod: function () {
         PageMethods.DeliveryTimeCalc(pageMethodConcept.callback);
    },
    callback: function (result) {
        alert(result);
        //return result;
        }
    }
    //window.onload = pageMethodConcept.callServerSideMethod;
</script>

but the problem is that it is not returning the value (hh:mm) I am getting a alert box which contains output like

function () {
    PageMethods.DeliveryTimeCalc(pageMethodConcept.callback);
}

even if I use return I am getting the same value

but if I use

window.onload = pageMethodConcept.callServerSideMethod;

I am getting a alert box which contains output like hh:mm

Please Help!

1
  • Fyi, language="javascript" is obsolete and not necessary. Commented Feb 24, 2012 at 11:26

2 Answers 2

1

Try simply changing:

var time = pageMethodConcept.callServerSideMethod();

with trailing () : you have to assign the return value of the function to the variable, not the function itself, but:

window.onload = pageMethodConcept.callServerSideMethod;

works as expected because you're assigning an handler to an event and you have no parameters to pass along with the function: this in fact it could be written as well as:

window.onload = function() {
    pageMethodConcept.callServerSideMethod();
}
Sign up to request clarification or add additional context in comments.

1 Comment

So what should i do now so i need the result to be returned
0

Thank you guys for helping but i have found the solution myself

Sol 1 Using Web Services

http://markitup.com/WebServices/TimeZones.asmx?op=CurrentDateTime

this is a web service in which we have to enter the name of the time zone Ex:(India Standard Time)

Sol 2

Write a method in the pageload and in that method write your code. When you have to return the result place the result in a labe text and make the visibility of the label to false (Note: You can not find the label in javascript if the visibility is set to false So do this instead of making visibility false. style="display: none;" this does the same but in JavaScript you can find the label) you can find the label in javascript by using

var time = $("#lbl_time").text();

Since we coded the jquery as $(document).ready(function () the jquery will be executed only after the page load is executed

So Problem Solved

Thank You

-Krishna Thota

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.