2011-08-07 24 views
0

問:爲什麼在文本更改事件後滾動「向上」? (奇怪的行爲)

我有一個gridview中包含文本框作爲模板field.The網格視圖存在更新面板中。我的問題是:

當文本更改事件已經觸發時,感覺像瀏覽器的jump類似於(回發)的行爲。 但它不是回發。我不知道爲什麼會發生這種奇怪的行爲。

我的aspx:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <ContentTemplate> 
      <asp:Panel ID="pnl_research" runat="server" CssClass="pnl"> 
       <div id="detailsDiv" align="center" style="width: 800px;"> 
        <table border="0" width="98%"> 
         <tr> 
          <td align="center"> 
           <div class="grid" dir="rtl"> 
            <div class="grid" dir="rtl"> 
             <div class="rounded"> 
              <div class="top-outer"> 
               <div class="top-inner"> 
                <div class="top"> 
                 <h2> 
                  <asp:Label ID="Label35" runat="server" Text="جدول التقييم العام"></asp:Label></h2> 
                </div> 
               </div> 
              </div> 
              <div class="mid-outer"> 
               <div class="mid-inner"> 
                <div class="mid"> 
                 <asp:GridView Width="100%" ID="gv_Evaluation" CssClass="datatable" AllowSorting="True" 
                  runat="server" AutoGenerateColumns="False" AllowPaging="True" GridLines="None" 
                  OnRowDataBound="gv_Evaluation_RowDataBound"> 
                  <EmptyDataTemplate> 
                   <table style="width: 100%;"> 
                    <tr> 
                     <td> 
                     &nbsp; 
                    </tr> 
                    <tr> 
                     <td align="center"> 
                      <asp:Label ID="Label4" runat="server" Font-Size="16pt" Text="&#1604;&#1575; &#1610;&#1608;&#1580;&#1583; &#1576;&#1610;&#1575;&#1606;&#1575;&#1578;"></asp:Label> 
                     </td> 
                    </tr> 
                    <tr> 
                     <td> 
                      &nbsp; 
                     </td> 
                    </tr> 
                   </table> 
                  </EmptyDataTemplate> 
                  <Columns> 
                   <asp:TemplateField HeaderText="م"> 
                    <ItemTemplate> 
                     <asp:Label ID="lblSerial" runat="server"></asp:Label></ItemTemplate> 
                   </asp:TemplateField> 
                   <asp:BoundField HeaderText="نوعية النشاط" DataField="activityType" /> 
                   <asp:BoundField HeaderText="أوزان النشاط" DataField="activityWeight" /> 
                   <asp:TemplateField HeaderText="التقييم"> 
                    <ItemTemplate> 
                     <telerik:RadTextBox ID="txt_evaluateWeights" runat="server" AutoPostBack="True" OnTextChanged="txt_evaluateWeights_TextChanged" 
                      hideData='<%#((GridViewRow)Container).RowIndex%>'> 
                     </telerik:RadTextBox> 
                     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_evaluateWeights" 
                      Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator></ItemTemplate> 
                   </asp:TemplateField> 
                   <asp:BoundField HeaderText="التقييم الذاتي" DataField="activitySelf" /> 
                   <asp:BoundField HeaderText="تقييم رئيس القسم" DataField="activityBoss" /> 
                   <asp:BoundField HeaderText="تقييم العميد" DataField="activityDean" /> 
                  </Columns> 
                  <RowStyle VerticalAlign="Top" CssClass="row" /> 
                 </asp:GridView> 
                </div> 
               </div> 
              </div> 
              <div class="bottom-outer"> 
               <div class="bottom-inner"> 
                <div class="bottom"> 
                </div> 
               </div> 
              </div> 
             </div> 
            </div> 
           </div> 
          </td> 
         </tr> 
        </table> 
       </div> 
      </asp:Panel> 
     </ContentTemplate> 
    </asp:UpdatePanel> 

編輯:

我刪除

此行hideData='<%#((GridViewRow)Container).RowIndex%>'


protected void txt_evaluateWeights_TextChanged(object sender, EventArgs e) 
     { 

      calc(); 
      int index = ((System.Web.UI.WebControls.GridViewRow)(((RadTextBox)sender).Parent.NamingContainer)).DataItemIndex; 
      //int index = int.Parse(((RadTextBox)sender).Attributes["hideData"]); 
      ((RadTextBox)gv_Evaluation.Rows[index + 1].Cells[3].FindControl("txt_evaluateWeights")).Focus(); 
     } 

仍然是同樣的問題!


EDIT2:

protected void gv_Evaluation_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 

     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      Label lblSerial = (Label)e.Row.FindControl("lblSerial"); 
      lblSerial.Text = ((gv_Evaluation.PageIndex * gv_Evaluation.PageSize) + e.Row.RowIndex + 1).ToString(); 

      RadTextBox txt = e.Row.FindControl("txt_evaluateWeights") as RadTextBox; 
      ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(txt); 
     } 


    } 

還是同樣的問題!


EDIT3:

我知道這個問題,但我不知道如何解決它:

問題是此行的結果:

((RadTextBox)gv_Evaluation.Rows[index + 1].Cells[3].FindControl("txt_evaluateWeights")).Focus(); 

但我需要這行代碼。如何防止Focus()方法跳轉到頁面頂部。

+0

請,任何幫助解決我的問題 –

+0

我編輯我的問題 –

回答

1

您確定這不是回傳嗎?你應該定義你的觸發器。

我相信這可能是一個類似的問題,一個解決方案: Full postback triggered by LinkButton inside GridView inside UpdatePanel

+0

謝謝,但我做了你指的是我,但我仍然有同樣的問題。請看我編輯的問題。 –

+1

對不起,延遲迴復。問題已解決?那麼,這是一個AJAX調用,在那個調用中你想把焦點設置到下一個文本框?焦點是否設置爲正確的字段?或者是將焦點設置爲相同的文本框,無論您編輯哪一個? – Jacco

+0

沒關係。但解決方案在哪裏? ((RadTextBox)gv_Evaluation.Rows [index + 1] .Cells [3] .FindControl(「txt_evaluateWeights」))。Focus();' 是的,我將它設置爲正確的字段。我把重點放在想要輸入數據的文本框中。 –

2

有必要在這裏#符號(以下2號線):

<telerik:RadTextBox ID="txt_evaluateWeights" runat="server" AutoPostBack="True" OnTextChanged="txt_evaluateWeights_TextChanged" hideData=' 
<%#((GridViewRow)Container).RowIndex%>'> 

如果您使用空白#又名HTML名主播在它使得頁面跳轉到頂部的鏈接。

ex。頂部 會產生一個鏈接,點擊時會跳轉到頁面頂部。您的OnTextChange事件看起來像包含#可能導致您的問題。

+0

嗯,可能是但這是綁定表達式(HTTP:/ /msdn.microsoft.com/en-us/library/bda9bbfx%28v=vs.71%29.aspx)。是否有任何替代'#'? –

+0

刪除此行,但仍然是相同的問題 –

+0

-1,是一個錨中的#使頁面跳轉。但是,然後在給定的代碼中搜索一個隨機#並不是一種解決問題的方法。 – Jacco