0

Q:

I have a gridview which contains text box as a template field.The grid view exists in an update panel . My problem is:

When the text changed event has fired , feel like a jumpof the browser similar to the behavior of (post back).but it isn't a post back. I don't know why this strange behavior happened.

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

EDIT:

I remove

this line 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();
        }

still the same problem!!


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);  
        }


    }

still the same problem!!


EDIT3:

I knew the problem , but i don't know how to fix it:

the problem is as a result of this line:

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

but i need this line of code. How to prevent the Focus() method from making a jump to the top of the page.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

2 Answers2

2

Is the # symbol necessary here (line 2 below):

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

If you use a blank # aka html name anchor in a link it makes the page jump to the top.

ex. Top would make a link that when clicked on would jump you to the top of the page. Your OnTextChange event looks like it contains a # that might be causing your issue.

MaxGeek
  • 1,105
  • 6
  • 21
  • 32
1

Are you sure this is not a Postback? You should define your triggers.

I believe this might be a similar problem, with a solution: Full postback triggered by LinkButton inside GridView inside UpdatePanel

Community
  • 1
  • 1
Jacco
  • 3,251
  • 1
  • 19
  • 29
  • thanks, but i did what u refer to me and still i have the same problem.look to my edited question please. – Anyname Donotcare Aug 07 '11 at 11:32
  • 1
    Sorry, late reply. Problem already solved? So, this is an AJAX-call and in that call you want to set focus to the next textbox? Is the focus set to the correct field? Or is the focus set to the same textbox, no matter which one you edit? – Jacco Aug 09 '11 at 13:22
  • Never mind. but where is the solution ? the problem as i said: `((RadTextBox)gv_Evaluation.Rows[index + 1].Cells[3].FindControl("txt_evaluateWeights")).Focus();` yeah i set it for the correct field . and i put the focus on the intended textbox to enter the data in. – Anyname Donotcare Aug 10 '11 at 07:47