1

I am using jquery ui datepicker in my asp.net page inside gridview header row like this:

 <asp:TemplateField SortExpression="Published" > 
            <HeaderTemplate>
              <span id="spDate">
                <asp:Button ID="Button2" runat="server"  Text="<%$ Resources:Vacancies, DateRange %>" CssClass="chenge-a" />
                </span>

            </HeaderTemplate>
            <ItemTemplate>
                <asp:Literal ID="PublishedLiteral" runat="server" 
                    Text='<%# DateTime.Parse(Eval("Published", "{0:m}")) == DateTime.Now.Date ? string.Format("<span class=greenText>{0}</span>", GetGlobalResourceObject("Vacancies", "VacancyToday")) : DateTime.Parse(Eval("Published", "{0:d}")).ToString("dd MMM") %>' />
                      -
                      <asp:Literal ID="DeadlineLiteral" runat="server" 
                    Text='<%# DateTime.Parse(Eval("Deadline", "{0:m}")) == DateTime.Now.Date ? string.Format("<span class=orangeText>{0}</span>", GetGlobalResourceObject("Vacancies", "VacancyToday")) : DateTime.Parse(Eval("Deadline", "{0:d}")).ToString("dd MMM") %>' />
            </ItemTemplate>
        </asp:TemplateField>

and then using following Jquery code to change the value of a textbox:

   <script type="text/javascript">
        $(document).ready(function () {
  $(".chenge-a").datepicker({
                onSelect: function (value, date) {
                   alert('The chosen date is ' + value);
                    $(".txt").val(value);
                }
            });

            $(".txt").on('change', function () {
                alert('I am pretty sure the text box changed');
            });
 });

Textbox is like this:

<asp:TextBox ID="txtdatetemp" runat="server" AutoPostBack="True" 
    ontextchanged="txtdatetemp_TextChanged" class="txt"  ></asp:TextBox>

and it is outside gridview. I have attached server side text_changed event to it

   protected void txtdatetemp_TextChanged(object sender, EventArgs e)
        {

        }

but it is not called. Neither client side function

 $(".txt").on('change', function () 

is called.

I want to rebind the gridview on change of date in jquery ui datepicker. Please suggest solution to it.

Thanks

1 Answer 1

1

I tried this:

 $(".chenge-a").datepicker({              
                onSelect: function (value, date) {                   
                    $(".txt").val(value);
                    $(".txt").change(function () {
                    }).triggerHandler('change');
                    e.preventDefault();
                }
            });

and it worked.

Sign up to request clarification or add additional context in comments.

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.