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 jump
of 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>
</tr>
<tr>
<td align="center">
<asp:Label ID="Label4" runat="server" Font-Size="16pt" Text="لا يوجد بيانات"></asp:Label>
</td>
</tr>
<tr>
<td>
</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.