Advertisement

10.07.2008 at 02:33PM PDT, ID: 23795449
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.9

Why is the dropdownlist in my web part losing the values?

Asked by SamiVV in MOSS-Sharepoint

Tags: , ,

Hi,

I've been trying to add two dropdown lists and a button to a web part. I want to pass the values a user selects in the dropdowns to a filter on that web part.

However, when the values are submitted (either with a button click on a SelectedIndexChanged event, the page posts, but the values are lost.)

In an effort to test, I'm just tyring to write the passed values to the page, but they always return null. If I use an IsPostback event in the CreateChildControls method, the dropdownlists lose all of their values (though from what I've read, I thought they should keep them)?

I'm sure I'm missing something on how ViewState works with SharePoint. Any help is greatly appreciated. (Code snippet below.)

Thanks!

Sami


        public void CreateDDLsAndButtons()
        {
            try
            {
                ddlOption1.ID = "ddlOption1";
                ddlOption2.ID = "ddlOption2";

                ListItem liTitle = new ListItem();
                liTitle.Value = "Title";
                liTitle.Text = "Title";
                ddlOption1.Items.Add(liTitle);
                ddlOption2.Items.Add(liTitle);

                ListItem liStudent = new ListItem();
                liStudent.Value = "Author";
                liStudent.Text = "Student";
                ddlOption1.Items.Add(liStudent);
                ddlOption2.Items.Add(liStudent);

               //If I disable the AutoPostBack, the SelectedIndexChanged doesn't get called, though I'm not sure it's getting called when this is enabled, although the page does post back.
                ddlOption1.AutoPostBack = true;
                ddlOption2.AutoPostBack = true;
               
                ddlOption1.SelectedIndexChanged += new System.EventHandler(this.ddlOption1_SelectedIndexChanged);
                ddlOption2.SelectedIndexChanged += new System.EventHandler(this.ddlOption2_SelectedIndexChanged);

                btnSubmit.ID = "btnSubmit";
                btnSubmit.Text = "Go";
                btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
               
            }
            catch (Exception ex)
            {
                WriteToEventLog(ex.ToString(), "Multigenre Research", EventLogEntryType.Error, "Application");
            }
           
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
           
                CreateDDLsAndButtons();
           
            this.Controls.Add(ddlOption1);
            this.Controls.Add(ddlOption2);
            this.Controls.Add(btnSubmit);
            FunctiontoUseTheValues(sOption1, sOption2);
           
        }
        private void ddlOption1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
           //I've tried putting this in a session var as well and no luck.
            sOption1 = ddlOption1.SelectedItem.Value;
            HttpContext.Current.Response.Write("<br />1: " + HttpContext.Current.Session["sOption1"]);
        }

        private void ddlOption2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            sOption2 = ddlOption2.SelectedItem.Value;
            HttpContext.Current.Response.Write("<br />2: " + HttpContext.Current.Session["sOption2"]);
        }

        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            sOption1 = ddlOption1.SelectedItem.Value;
            HttpContext.Current.Response.Write("<br />Option 1 value: " + sOption1);
           
        }Start Free Trial
 
Loading Advertisement...
 
[+][-]10.08.2008 at 02:14AM PDT, ID: 22667226

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MOSS-Sharepoint
Tags: Microsoft, SharePoint, 2007
Sign Up Now!
Solution Provided By: JamieMcAllister
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.08.2008 at 01:36PM PDT, ID: 22673124

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628