0

I'm developing a web part for sharepoint 2010. I have a dropdown with an event. On change it should show one label or another, depending on the value but this is not working. I did put autopostback to true but i dont want the whole page to be loaded everytime i click on the dropdown.

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 Answer 1

1

You just need to wrap your dropdown in an update panel

appears to be a good example

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.