Web部件Sharepoint - 下拉SelectIndexChanged以设置可见性不起作用

时间:2013-06-25 10:31:57

标签: c# asp.net sharepoint web-parts

我正在为sharepoint 2010开发一个Web部件。我有一个事件的下拉列表。在更改时,它应显示一个或另一个标签,具体取决于值,但这不起作用。我确实把autopostback设置为true但我不希望每次点击下拉列表时都会加载整个页面。

protected override void CreateChildControls()
    {
        toolPartPanel = new Panel();
        ddl = new DropDownList();
        ddl.ID = "ddl";
        ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
        ddl.EnableViewState = true;
        ddl.Items.Add("a");
        ddl.Items.Add("b");

        label1 = new Label();
        label1.Text = "a selected";
        label1.Visible = false;

        label2 = new Label();
        label2.Text = "b selected";
        label2.Visible = false;

        this.Controls.Add(label1); this.Controls.Add(label2);
        this.Controls.Add(ddl);
        this.Controls.Add(toolPartPanel);
        base.CreateChildControls();
    }

    void ddl_SelectedIndexChanged(object sender, EventArgs e) 
    {
        Selected = ddl.SelectedValue.ToString();
        if (Selected == "a")
        {
            label1.Visible = true;
        }
        else
        {
            if (Selected == "b")
            {
                label2.Visible = true;
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

您只需将下拉包装在更新面板中

即可

似乎是一个很好的例子

text is not allowed between the opening and closing tags update panel