【问题标题】:calendar extender controls in Gridview causes unnecessary postbackGridview 中的日历扩展器控件导致不必要的回发
【发布时间】:2017-04-23 14:37:23
【问题描述】:

在下面的代码中,如果我在 Gridview 中使用日历扩展器控件和文本框,我会收到不必要的回发。这意味着在以下代码中运行时 UpdateEmployeeInAppForm 被调用了两次。在 Gridview 之外它工作正常。任何机构都可以帮助我吗?

<asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="false" ItemType="Employee">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <table> <tr>
                                <td>Date Of Birth</td>
                                <td colspan="3">
                                    <asp:TextBox ID="tbDOB" runat="server" OnTextChanged="UpdateEmployeeInAppForm" AutoPostBack="true" Text='<%# Item.DOB%>'></asp:TextBox>

                                    <asp:CalendarExtender ID="tbDOB_CalendarExtender" runat="server" Format="dd MMMM yyyy" SelectedDate='<%# Item.DOB%>'
                                        Enabled="True" TargetControlID="tbDOB" ></asp:CalendarExtender>
                                </td>
                            </tr>
</table>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

【问题讨论】:

    标签: asp.net datepicker calendar postback ajaxcontroltoolkit


    【解决方案1】:

    这是我找到的解决方案:

                                  <asp:TextBox ID="tbDOB" runat="server" OnTextChanged="UpdateEmployeeInAppForm"  AutoPostBack="true" 
                                            Text='<%#Item.DOB.HasValue ? Item.DOB.Value.Date.ToString("dd MMMM yyyy") : "" %>'></asp:TextBox>                                        
                                        <asp:CalendarExtender ID="tbDOB_CalendarExtender" runat="server"   Format="dd MMMM yyyy"                                           
                                            Enabled="True" TargetControlID="tbDOB" ></asp:CalendarExtender>
    

    从日历扩展器控件中删除 SelectedDate='' 并使文本框和日历中的格式相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 2021-09-18
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多