我有一个gridview,文本框,更新面板内的下拉菜单,它运行良好,但问题是,当我点击任何下拉菜单而不是它更改滚动回整个页面顶部并刷新它,为什么?
代码:
<asp:UpdatePanel ID="updGridViewSMS" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<label><b>Search By Date Range</b></label>
<asp:Label ID="lblDateFrom" runat="server" Text="From"></asp:Label>
<asp:TextBox ID="txtFromDate" runat="server" ></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderFromDate" Format="dd/MMM/yyyy" TargetControlID="txtFromDate" runat="server">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ControlToValidate="txtFromDate" Display="None" ErrorMessage=""
ForeColor="Red" >
</asp:RequiredFieldValidator>
<asp:Label ID="lblDateTo" runat="server" Text="To"></asp:Label>
<asp:TextBox ID="txtToDate" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderToDate" Format="dd/MMM/yyyy" TargetControlID="txtToDate" runat="server">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
ControlToValidate="txtToDate" Display="None" ErrorMessage=""
ForeColor="Red" >
</asp:RequiredFieldValidator>
<asp:Button ID="btnSearchByDate" CssClass="btn btn-success" runat="server" Text="Search"
ClientIDMode="Static" OnClick="btnSearchByDate_Click" />
<asp:ValidationSummary
HeaderText="Requires Date Range:"
DisplayMode="SingleParagraph"
EnableClientScript="true"
ForeColor="Red"
runat="server" ID="ValidationSummary1"/>
<label runat="server" id="lblSelectionMessage" style="color:navy; font-size:12px; font-style:italic" visible="false">
Please select one validity dropdown at a time
</label>
<asp:GridView ID="GridViewSmsComplaints" AllowPaging="True" PageSize="5" runat="server" AutoGenerateColumns="False" CssClass="mGrid" BorderColor="#333333" Width="650px" OnRowDataBound="GridViewSmsComplaints_RowDataBound" OnPageIndexChanging="GridViewSmsComplaints_PageIndexChanging" >
<Columns>
<asp:BoundField HeaderText="Sms ID" DataField="ID" />
<asp:BoundField HeaderText="Recieving Date" DataField="RecievingDate" />
<%--<asp:BoundField HeaderText="ToMobileNo" DataField="ToMobileNo" /> --%>
<asp:BoundField HeaderText="Incoming No" DataField="FromMobileNo" />
<asp:BoundField HeaderText="Complaint" DataField="Message" >
<ItemStyle Wrap="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="Is Valid?">
<ItemTemplate>
<%--<asp:CheckBox ID="ckboxIsComplaint" runat="server" />--%>
<asp:DropDownList ID="ddlIsComplaint" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlIsComplaint_SelectedIndexChanged">
<asp:ListItem Text="-Select-" Value="-1"></asp:ListItem>
<asp:ListItem Text="Invalid" Value="0"></asp:ListItem>
<asp:ListItem Text="Valid" Value="1"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Panel ID="pnlBoxesDropDowns" runat="server">
<label>Complainant</label>
<asp:TextBox ID="txtComplainant" runat="server" CssClass="textField_width"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqFieldValdiatorComplainant" runat="server" ControlToValidate="txtComplainant" ErrorMessage="Complainant is Required" ForeColor="Red" SetFocusOnError="True" ValidationGroup="Complaints">Complainant is Required
</asp:RequiredFieldValidator>
<label style="width:400px">Region</label>
<asp:DropDownList ID="ddlRegions" runat="server" CssClass="DropDown_Width" Width="147px" OnSelectedIndexChanged="ddlRegions_SelectedIndexChanged" AppendDataBoundItems="True" AutoPostBack="true" >
<asp:ListItem Value="-1" Selected="True">-Select-</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqFieldValidatorRegions" runat="server"
ControlToValidate="ddlRegions" ErrorMessage="Region is Required" InitialValue="-1"
ForeColor="Red" ValidationGroup="Complaints">Region is Required</asp:RequiredFieldValidator>
<label style="width:400px">District</label>
<asp:DropDownList ID="ddlDistricts" runat="server" CssClass="DropDown_Width" Width="147px" OnSelectedIndexChanged="ddlDistricts_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqFieldValidatorDistricts" runat="server"
ControlToValidate="ddlDistricts" ErrorMessage="Region is Required" InitialValue="-1"
ForeColor="Red" ValidationGroup="Complaints">District is Required</asp:RequiredFieldValidator>
<label>PoliceStations</label>
<asp:DropDownList ID="ddlPoliceStations" runat="server" Width="147px" CssClass="DropDown_Width">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqFieldValidatorPoliceStations" runat="server"
ControlToValidate="ddlPoliceStations" ErrorMessage="Police Station is Required" InitialValue="-1"
ForeColor="Red" ValidationGroup="Complaints">Police Station is Required</asp:RequiredFieldValidator>
<label>Priority</label>
<asp:DropDownList ID="ddlPriority" runat="server">
<asp:ListItem Text="Top" Value="1"></asp:ListItem>
<asp:ListItem Text="Normal" Value="2"></asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<br />
<br />
<asp:Timer runat="server" Interval="60000" ID="RefreshSmsComplaints" OnTick="RefreshSmsComplaints_Tick" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RefreshSmsComplaints" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnSendSms" ValidationGroup="Complaints" runat="server" CssClass="btn btn-success"
OnClick="btnSendSms_Click" Text="Send Sms" />
<asp:Button ID="btnGenerateReport" CssClass="btn btn-success" runat="server" Text="Generate Report"
ClientIDMode="Static" OnClick="btnGenerateReport_Click" />
答案 0 :(得分:0)
autopostback =“true”语句会导致这种情况发生。这是必需的,您希望在更新下拉列表后运行服务器端事件。如果要阻止回发,从而刷新页面,则应删除autopostback =“true”语句。这样做可以防止抛出'OnSelectedIndexChanged'事件。为了解决这个问题,您可以为此事件创建等效的javascript客户端功能。
Serverside事件和客户端事件是两种不同类型的事件。如果您确实知道这意味着什么,那么您应该对此进行一些研究。
答案 1 :(得分:0)
将更新模式设置为包含DropDownList的更新面板的条件,并设置ChildrenAsTriggers = false。如果要更新下拉列表中的任何值,则ChildrenAsTriggers = false不会刷新页面。