下拉列表重置

时间:2013-05-08 14:04:53

标签: c# sharepoint webforms controls updatepanel

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

这是标记,

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

1 个答案:

答案 0 :(得分:1)

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

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

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