Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to customize the SearchBoxEx-Control. So I made a Webpart which inherits from SearchBoxEx. In the CreateChildControls I put an updatepanel and two dropdownlists.

Every time I select something in the dropdownbox it makes a postback, that's correct. But It makes a recreates all controls in updatepanel so that nothing changes. I have to use a normal webpart (no visual webpart because of using searchboxex). The class is public class ExtendedSearch : SearchBoxEx

[ToolboxItemAttribute(false)]
public class ExtendedSearch : SearchBoxEx
{
    UpdatePanel mainUpdatePanel;
    UpdateProgress progressControl;
    Button checkTimeButton;
    Label timeDisplayLabel;
    DropDownList category;
    DropDownList subcategory;

    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        this.DropDownModeEx = DropDownModesEx.ShowDD;

        mainUpdatePanel = new UpdatePanel();
        mainUpdatePanel.ID = "updateAjaxDemoWebPart";
        mainUpdatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
        mainUpdatePanel.RenderMode = UpdatePanelRenderMode.Inline;

        category = new DropDownList();
        category.ID = "dropdownCategory";
        category.Items.Add("Cat 1");
        category.Items.Add("Cat 2");
        category.Items.Add("Cat 3");
        category.CssClass = "ms-sbscopes";
        category.Style["display"] = "inline";
        category.Style["margin-right"] = "10px";
        category.AutoPostBack = true;

        subcategory = new DropDownList();
        category.ID = "dropdownSubCategory";
        subcategory.Items.Add("SubCat 1");
        subcategory.Items.Add("SubCat 2");
        subcategory.Items.Add("SubCat 3");
        subcategory.CssClass = "ms-sbscopes";
        subcategory.Style["display"] = "inline";

        category.SelectedIndexChanged += new EventHandler(category_SelectedIndexChanged);

        mainUpdatePanel.ContentTemplateContainer.Controls.Add(category);
        mainUpdatePanel.ContentTemplateContainer.Controls.Add(subcategory);
        mainUpdatePanel.Triggers.Add(new AsyncPostBackTrigger()
        {
            ControlID = category.ID,
            EventName = "SelectedIndexChanged"
        });

        Control scopeDdl = FindControlRecursivly("SBScopesDDL", this);

        if (scopeDdl != null)
        {
            int index = scopeDdl.Parent.Controls.IndexOf(scopeDdl);
            scopeDdl.Parent.Controls.AddAt(index, mainUpdatePanel);
            scopeDdl.Parent.Controls.Remove(scopeDdl);
        }
    }

    private void category_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.subcategory.SelectedIndex = 2;
    }

    private Control FindControlRecursivly(string controlName, Control parentControl)
    {
        foreach (Control control in parentControl.Controls)
        {
            if (control.ID == controlName)
            {
                return control;
            }

            Control subControl = FindControlRecursivly(controlName, control);
            if (subControl != null)
            {
                return subControl;
            }
        }

        return null;
    }
  }
 }
 }
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Ok, it didn't work. When you use an updatepanel standalone in a webpart it works. It only updates the controls which should be updated.

When you inherit from searchboxex and put it there the updatepanel completly refreshes when making an AutoPostback=True.

My Solution was to use JQuery. I attached a Jquery-Function when the control changes its index. Before that I added all subdropdowns to the page and made them hidden with Jquery.

Hope that helps for your own solution.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.