如何在asp.net中将textbox autopostback设置为true时停止页面刷新?

时间:2014-04-16 11:24:49

标签: asp.net vb.net postback

我在gridview下有一个文本框,其autopostback属性为true,因此页面总是会刷新。但我不想刷新页面。

这是我的代码:

<asp:GridView ID="grdDates" runat="server" AutoGenerateColumns="False" Width="440px"
                                                    GridLines="None">
                                                    <Columns>
                                                        <asp:TemplateField HeaderText="Ds" HeaderStyle-Width="110px" HeaderStyle-ForeColor="#993300"
                                                            HeaderStyle-HorizontalAlign="Left">
                                                            <ItemTemplate>
                                                                <asp:TextBox ID="txt" runat="server" Onkeyup="" Text='<%#Eval("Ds") %>'
                                                                    OnTextChanged="txt_TextChanged" ToolTip='<%#Eval("Ds") %>' CssClass="txtboxDiff"
                                                                    Width="110px" onmouseover="setToolTip(this)" onblur="Check(this)" AutoPostBack="True"></asp:TextBox>

                                                                <asp:CalendarExtender ID="CalendarExtenderdocsdate" runat="server" PopupButtonID=""
                                                                    Format="dd-MM-yyyy" TargetControlID="txt">
                                                                </asp:CalendarExtender>
                                                            </ItemTemplate>
                                                        /Columns>
                                                </asp:GridView>

1 个答案:

答案 0 :(得分:0)

您可以将Gridview放在ajax更新面板中......

     <asp:GridView ID="grdDates" runat="server" AutoGenerateColumns="False" Width="440px"
              GridLines="None">
                 <Columns>
                <asp:TemplateField HeaderText="Ds" HeaderStyle-Width="110px" HeaderStyle-ForeColor="#993300"
                HeaderStyle-HorizontalAlign="Left">
                <ItemTemplate>
               <asp:UpdatePanel ID="UpdatePanel3" runat="server">
               <ContentTemplate>
                <asp:TextBox ID="txt" runat="server" Onkeyup="" Text='<%#Eval("Ds") %>'
                OnTextChanged="txt_TextChanged" ToolTip='<%#Eval("Ds") %>' CssClass="txtboxDiff"
                Width="110px" onmouseover="setToolTip(this)" onblur="Check(this)" AutoPostBack="True">   </asp:TextBox>

               <asp:CalendarExtender ID="CalendarExtenderdocsdate" runat="server" PopupButtonID=""
               Format="dd-MM-yyyy" TargetControlID="txt">
               </asp:CalendarExtender>
               </ContentTemplate>


              <Triggers>
              <asp:AsyncPostBackTrigger ControlID="txt" />
              </Triggers>    


               </asp:UpdatePanel>
               </ItemTemplate>
               </Columns>
               </asp:GridView>

放置一名剧本管理员..

<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>