views:

392

answers:

3

This is so frustrating. I've done this a million times! For some reason, Firefox won't select an item in my drop down list. Why? (It works find in IE)

ASPX PAGE

<asp:DropDownList ID="ddlPlan" runat="server" CssClass="TDSelect" Width="250px" AutoPostBack="true" DataTextField="Plan_Name" DataValueField="Plan_ID" />

ASPX.VB CODE BEHIND

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Try

      GetQueryStringInfo()

      If Not Page.IsPostBack Then   
        InitDropDowns()
        LoadTasks()
        SetUI()  
      End If

    Catch ex As Exception
      lblResults.Text = "Error loading page: " & TeamDynamix.Error.TDError.HandleException(Me.DbConnStr, Me.UID, ex) & ": " & ex.Message
    End Try

  End Sub

  Private Sub InitDropDowns()

    'Plan'
    'LOAD PLANS'
    Using oDR As SqlClient.SqlDataReader = Common.GetSPDataReader(Me.DbConnStr, "PlansSelect", _
                  Common.MP("@UID", SqlDbType.VarChar, 40, Me.UID), _
                  Common.MP("@TID", SqlDbType.Int, 4, Me.TID))

      If oDR.HasRows Then   
        ddlPlan.DataSource = oDR
        ddlPlan.DataBind()   
      End If

      'Clean up'
      oDR.Close()

    End Using

    'INSERT BLANK ITEM'
    ddlPlan.Items.Insert(0, "")

    'IF PLANID IS SET, SELECT APPROPRIATE PLAN'
    If PlanID > 0 Then    
      If ddlPlan.Items.FindByValue(PlanID) IsNot Nothing Then
        ddlPlan.SelectedValue = PlanID
      End If    
    End If

  End Sub

I've examined the rendered HTML by viewing source in FireFox. It appears to create the element correctly, and all the options (values and text are set correctly), and it also puts selected="selected" on the appropriate item in the list! So I'm not sure why the item doesn't appear selected. NOTE: It's now working, read to end of this question to see the new "real" question...

RENDERED HTML

<select id="ddlPlan" class="TDSelect" style="width: 250px;" onchange="javascript:setTimeout('__doPostBack(\'ddlPlan\',\'\')', 0)" name="ddlPlan">
  <option value=""/>
  <option value="517">(Copy of) AAA</option>
  <option value="500">(Copy of) andrew test</option>
  <option value="249">(Copy of) Test</option>
  <option value="359">Brandon's Test</option>
  <option value="472">BTEST2</option>
  <option value="1498">Date Issue Test</option>
  <option value="1516">Date Issue Test</option>
  <option value="1529">Date Issue Test</option>
  <option value="367">Import</option>
  <option value="91">Task Import</option>
  <option value="331">Task Plan Import</option>
  <option value="332">Task Plan Template Test </option>
  <option value="520">test 456</option>
  <option value="1464">test 456</option>
  <option value="1520">test 456</option>
  <option value="1480">Test Checking Out</option>
  <option value="1527">Test Plan</option>
  <option value="560">TestPlan-B</option>
  <option value="1465">TestPlan-B</option>
  <option value="1521">TestPlan-B</option>
  <option value="605" selected="selected">Work Items</option>
</select>

IT JUST STARTED WORKING
I just posted and answer to this because it just started working for no apparent reason whatsoever. The question then becomes: Is there some sort of caching or any other mechanism in FireFox that would cause this behavior?

+1  A: 

I noticed that you are using "Plan_ID" in the HTML and PlanID in your code behind. They should be the same.

Coov
The Plan_ID field is an integer that is returned from the stored procedure. The PlanID variable is a private variable on the page class which is extracted from the query string. These definitely DON'T have to match. The databinding on the drop down list basically calls oDR("Plan_ID") to get the value for each item it binds to the list. -1
Brandon Montgomery
+1  A: 

Interesting, do you have !Page.IsPostback wrapping around the code that binds the DropDown? If the answer is no, the DropDown is gonna be re-bound on every postback and the selected value shall be lost.

Genady Sergeev
It only runs if the page is not a postback. I'll make and edit to the question to reflect this.
Brandon Montgomery
I copied the output into an html file, opened it in Firefox and it worked with "Work Items" being the selected value.
Coov
A: 

OK, for some reason this just started working. I swear it wasn't working before, but I didn't change anything and it just started working. Could some sort of caching have been causing this issue or anything like that?

Brandon Montgomery
What exactly was the problem? Did it populate the dropdown list, but not auto-select the one you had marked with selected="selected"?
Shawn Steward
Shawn - that's right. You can see that from the rendered HTML I posted on the question. It did not appear as the selected item in the drop down list.
Brandon Montgomery