3

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

这是标记,

<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 不会重置,但仍然不会触发方法背后的代码。

4

1 回答 1

1

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

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

        if (!IsPostBack)
        {
            BindDropDownList();
        }
    }
于 2013-08-20T05:40:31.853 回答