Page Flickering on Dropdown change

时光总嘲笑我的痴心妄想 提交于 2019-12-13 01:24:18

问题


I'm using a drop down list to select the customer. The page flicker twice on selecting the customer and I don't know how to rectify it. Can someone please help me solve the problem?

My Drop Down SelectedIndexChange Code

protected void ReceiverDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ReceiverDropDown.SelectedValue != null && ReceiverDropDown.SelectedValue != "0")
    {            
        string benId = ReceiverDropDown.SelectedValue;
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "AddDetails('" + benId + "');", true);
    }
}

Code using Update Panel

<td>
    <asp:UpdatePanel runat="server" ID="updTerms" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:DropDownList Width="180px" CssClass="select_quo_one" ID="ReceiverDropDown" 
                runat="server" AutoPostBack="true"
                OnSelectedIndexChanged="ReceiverDropDown_SelectedIndexChanged">
            </asp:DropDownList>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </ContentTemplate>
    </asp:UpdatePanel>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ReceiverDropDown" />
    </Triggers>
</td>


回答1:


To avoid page flickering you can make use of update panel. Bind the DropDownList inside update panel.

Markup:

<asp:UpdatePanel runat="server" ID="updTerms">
    <ContentTemplate>
        <asp:DropDownList ID="ReceiverDropDown" runat="server">
    </asp:DropDownList>
    </ContentTemplate>
    <Trigger>
        <asp:AsyncPostBackTrigger ControlID="ReceiverDropDown"  />
    </Trigger>
</asp:UpdatePanel>



回答2:


Use update field like:

<asp:UpdatePanel ID="updpnlRefresh" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:TextBox ID="txtQuantity"  runat="server" Width="50px"
                     onkeydown="ClearErrorMessages()" onkeypress="return allowNumeric(event)"
                     ontextchanged="txtQuantity_TextChanged"  Text='<%#Eval("Quantity") %>'
                     AutoPostBack = "true"  ondragstart="return false;"
                     ondrop="return false;" />               
    </ContentTemplate>
</asp:UpdatePanel>


来源:https://stackoverflow.com/questions/23606299/page-flickering-on-dropdown-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!