开发者

Why scrolling "Up" after text changed event? (Weird action)

开发者 https://www.devze.com 2023-03-26 05:24 出处:网络
Q: I have a gridview which contains text box as a template field.The grid view exists in an update panel . My problem is:

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>
                开发者_如何学C                                                <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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号