下拉列表重置 [英] Drop Down List resets

查看:79
本文介绍了下拉列表重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试选择一个项目时,我的下拉列表会重置为默认值,并且当我放置换行符并尝试对其进行调试时,它也不会触发方法后面的代码:

My drop down list resets to default when I try to select a item, and it also doesn't trigger's code behind method when I put a line break and try to debug it:

此处是标记,

<script type="text/javascript">
    function bringPOPup() 
    {     
        $.blockUI({message: $('#anotherUP'), css: { width: '600px' } });
    }
</script>



<div id="anotherUP" style="display: none; cursor: default">
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
        <ContentTemplate>
                <asp:DropDownList ID="drop1" runat="server" EnableViewState="true" AutoPostBack="true" OnSelectedIndexChanged="Drop1_SelectedIndexChanged"/>
        </ContentTemplate>
     <Triggers>
        <asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" />
    </Triggers>
    </asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
    <ContentTemplate>
        <input type="button" id="Button3" value="Click me to Bring Pop Up" onclick="bringPOPup()" />
        <br />
    </ContentTemplate>
</asp:UpdatePanel>

这是后面的代码,

 public partial class myUserControl : UserControl
 {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDropDownList();
            }
        }

        protected void BindDropDownList()
        {
            using (SqlDataSource ds = new SqlDataSource(ConnectionString(), SelectCommand()))
            {
                System.Data.DataView dv = (System.Data.DataView)ds.Select(DataSourceSelectArguments.Empty);
                if (dv.Count > 0)
                {
                    drop1.DataSource = ds;
                    drop1.DataTextField = "UserName";
                    drop1.DataBind();
                    drop1.Items.Insert(0, "Please select a Username ");
                }
            }
            UpdatePanel2.Update();
        }

        protected void Drop1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //while debugging never hits break point.
        }
}

更新

如果我注释掉 UpdatePanel2 ,则DDL不会重置,但仍不会触发方法后面的代码。

If I comment out UpdatePanel2 then DDL doesn't reset but still doesn't trigger's code behind method.

推荐答案

这是共享点事件处理的常见问题。请尝试在页面加载中使用以下代码。

This is common problem with sharepoint event handling. Please try below code in page load.

    protected void Page_Load(object sender, EventArgs e)
    {
        Drop1.SelectedIndexChanged += new EventHandler(Drop1_SelectedIndexChanged);

        if (!IsPostBack)
        {
            BindDropDownList();
        }
    }

这篇关于下拉列表重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆