tamble / jquery-ui-daterangepicker

A JQuery UI based date range picker.
MIT License
184 stars 110 forks source link

How run vb.net code after date range selected #49

Closed webdevguyrg closed 8 years ago

webdevguyrg commented 8 years ago

I'm using this date range picker in an asp.net website. On my aspx page I have the date picker and an asp.net label. When the user selects the date range how can I automatically (similar to text_changed event) run my vb.net server-side code which, among other things, puts a message in the label based on their selection, such as "You selected the date range: 1/1/2015 thru 2/3/2015"? Thanks!

op16 commented 8 years ago

Try a __doPostBack() from our onChange callback.

webdevguyrg commented 8 years ago

Thanks!

I tried this, but it didn't work. I put a breakpoint on both page_load and cmdRun_Click. Any idea why?

        onChange: function () { 
            __doPostBack('#<%= cmdRun.ClientID%>', '')
        }

The button is a standard asp.net button....

       <asp:Button ID="cmdRun" runat="server" Text="Run" />
op16 commented 8 years ago

Any JS errors/warnings? Is the __doPostBack javascript function defined? Maybe http://stackoverflow.com/questions/1305954/asp-net-postback-with-javascript helps.

webdevguyrg commented 8 years ago

Yes. In fact, I even put an ALERT which never seems to be invoked...

  function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }

    $("#e7").daterangepicker({
        onOpen: function () {
            alert("onOpen");
        },
        onClose: function () {
            alert("onClose");
            __doPostBack($('#<%= cmdRun.ClientID%>').attr('name'), '');
        },
        onChange: function () {
            alert("onChange");
            __doPostBack($('#<%= cmdRun.ClientID%>').attr('name'), '');
        }
     });
op16 commented 8 years ago

I guess your button's id is not e7, but <%= cmdRun.ClientID%>