当使用jquery更改值时,不会触发asp.net文本框更改的事件

时间:2022-12-02 14:08:33

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

我在gridview标题行的asp.net页面中使用jquery ui datepicker,如下所示:

 <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:

然后使用以下Jquery代码更改文本框的值:

   <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

它在gridview之外。我已将服务器端text_changed事件附加到它

   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.

我想在jquery ui datepicker中更改日期时重新​​绑定gridview。请建议解决方案。

Thanks

谢谢

1 个解决方案

#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.

它工作。

#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.

它工作。