0

I have a problem that to control calenderextender in asp.net. For instance users cannot select backdate therefore I wrote Javascript function on aspx and call it aspx.cs . But I got error
"myfunction is not defined" enter image description here

enter image description here

my function

         <script type="text/javascript">

    function myfunction() {
        document.getElementById('txt_conferenceDate').onchange = function () {
            var selectedDateFromCalendar = new Date(this.value);
            var currentdate = new Date();
            var Diff = new Date(selectedDateFromCalendar) - currentdate;
            var diffDays = Math.ceil(Diff / (1000 * 3600 * 24));

            if ((selectedDateFromCalendar) - currentdate < 0) {
                alert("");
            }
        }
    }
</script>

call statement

 ScriptManager.RegisterClientScriptBlock(this, GetType(), "myfunction", "myfunction();", true);
user5695111
  • 111
  • 2
  • 13
  • 6
    So... what's the actual error? (What you're showing in the IDE picture seems to be a tooltip, not an error) – DBS Mar 28 '16 at 20:30
  • That's just a debugging breakpoint. Remove it, if you wish. Unless you have some other error that you're not showing here? – ManoDestra Mar 28 '16 at 20:47
  • I got error that "myfunction does not defined" @ManoDestra – user5695111 Mar 28 '16 at 21:11
  • Ensure that your script ordering has your myfunction ABOVE where you're trying to register it. – ManoDestra Mar 28 '16 at 21:21
  • I wrote the function in aspx page and call it in aspx.cs Page_Load @ManoDestra – user5695111 Mar 28 '16 at 21:27
  • Take a look at this: http://stackoverflow.com/questions/4994040/scriptmanager-registerstartupscript-code-not-working-why – ManoDestra Mar 28 '16 at 21:32
  • As suggested in the link given by @ManoDestra, you should call `ScriptManager.RegisterStartupScript` instead of `ScriptManager.RegisterClientScriptBlock` if you want to run the function after the page has loaded. – ConnorsFan Mar 29 '16 at 02:08

0 Answers0