2014-06-26 32 views
0

我有两个嵌套Gridviews,父是为文章和孩子是为评论。我想用一个时间间隔更新Post和Comments,所以我使用一个asp.net Timer。我的问题是TextBox是第一个Gridview在定时器Ticks时失去焦点。我在网上搜索了很多,一种可能的解决方案是将文本框从UpdatePanel中删除,但在这种情况下,我无法取出textBox。请帮助我,这是我的代码。textBox丢失重点嵌套Gridview

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
<asp:Timer ID="Timer1" Interval="10000" OnTick="Timer1_Tick" runat="server"> 
</asp:Timer> 
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> 
    </Triggers> 

    <ContentTemplate> 
     <%--post GridView--%> 
     <asp:GridView ID="posts" runat="server"> 
      <Columns> 
       <asp:TemplateField> 
        <ItemTemplate> 
         <%--Comments Gridview--%> 
         <asp:GridView ID="comments" runat="server"></asp:GridView> 
         <%--a Textbox and bUtton For sending new Comment--%> 
         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
         <asp:Button ID="Button1" runat="server" Text="Button" /> 
        </ItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
     </asp:GridView> 
    </ContentTemplate> 
</asp:UpdatePanel> 

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
    posts.DataSource = GetData(); 
    posts.DataBind(); 
} 

回答