Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Intermittent "jump" (loss of focus) between ASP dropdownlist controls in UpdatePanel

$
0
0

I am using a master page in my web project. The main content section on my page has an <asp:UpdatePanel> with UpdateMode="Always".  The UpdatePanel contains a FormView with an EditTemplate.  The FormView has eight <asp:DropDownList> controls which represent four pairs because each set is cascading.  For example, when the user picks a value from DropDownList1A, it will build DropDownList1B based on the newly selected value.  The newly selected value from DropDownList1A also gets removed from DropDownList2A, 3A, 4A, 5A and is not a selectable value (avoid duplicates).  When the user picks a value from DropDownList2A, it will build DropDownList2B based on the newly selected value, and so on:

<asp:DropDownList1A> <asp:DropDownList1B>
<asp:DropDownList2A> <asp:DropDownList2B>
<asp:DropDownList3A> <asp:DropDownList3B>
<asp:DropDownList4A> <asp:DropDownList4B>
<asp:DropDownList5A> <asp:DropDownList5B>

This functionality is correct and the proper values are displaying in the dropdownlist controls. The problem is...I am experiencing a random, intermittent "jump" or loss of focus when I mouse click/open a dropdownlist control.  Sometimes, within a period of 10 minutes, it may appear 2-3 times or more.  I'm not sure if it's related to the UpdatePanel (partial page postback) or how .NET is deciding what order to build each dropdownlist?  On the page, immediately following the dropdownlist controls, I have an <asp:panel> that has two buttons.  When this "jump" (loss of focus) occurs, focus goes to the first button in the panel.  I verified this by hitting the Enter key and the button's action executes.  Each dropdownlist has its own SqlDataSource and uses Control Parameters.  For example:

<asp:SqlDataSource ID="DropDownList1ASqlDataSource" runat="server" DataSourceMode="DataReader"
   ConnectionString="<%$ ConnectionStrings:PDMConnectionString %>" SelectCommandType="StoredProcedure"
   SelectCommand="spBuild_DropDownList1A" OnDataBinding="DropDownList1A_OnDataBinding">
   <SelectParameters>
       <asp:ControlParameter  ControlID="lstPractice" Name="ppval" Type="String" DefaultValue="%"
                              PropertyName="SelectedValue"  />
       <asp:ControlParameter  ControlID="DropDownList2A" Name="scp2val" Type="String" DefaultValue=" "
                              PropertyName="SelectedValue"  />
       <asp:ControlParameter  ControlID="DropDownList3A" Name="scp3val" Type="String" DefaultValue=" "
                              PropertyName="SelectedValue"  />
       <asp:ControlParameter  ControlID="DropDownList4A" Name="scp4val" Type="String" DefaultValue=" "
                              PropertyName="SelectedValue"  />
       <asp:ControlParameter  ControlID="DropDownList5A" Name="scp5val" Type="String" DefaultValue=" "
                              PropertyName="SelectedValue"  />
   </SelectParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1A" runat="server" AutoPostBack="true" Width="350px"  TabIndex="4"
            SelectedValue='<%# DataBinder.Eval(Container.DataItem,"sprac1") %>'
            DataTextField="dept_desc" DataValueField="sprac1"
            DataSourceID="DropDownList1ASqlDataSource"
            OnSelectedIndexChanged="DropDownList1A_OnSelectionChanged"
            OnDataBinding="DropDownList1A_OnDataBinding" >
</asp:DropDownList>

After a new value is picked in DropDownList1A, The "DropDownList1A_OnSelectionChanged" event passes values into the DropDownList1B SqlDataSource:

  protectedvoidDropDownList1A_OnSelectionChanged(object sender, EventArgs e)
  {
       
DropDownList ddlDropDownList1A = (DropDownList)sender;
        DropDownList ddlDropDownList2A = (DropDownList)FormView1.FindControl("DropDownList2A");
        DropDownList ddlDropDownList3A = (DropDownList)FormView1.FindControl("DropDownList3A");
        
DropDownList ddlDropDownList4A = (DropDownList)FormView1.FindControl("DropDownList4A");
        D
ropDownList ddlDropDownList5A = (DropDownList)FormView1.FindControl("DropDownList5A");
        
DropDownList ddlPNOM = (DropDownList)FormView1.FindControl("WebDropDownNOM");
        
        S
qlDataSourceDropDownList1BSqlDS =
           (SqlDataSource)FormView1.FindControl("DropDownList1BSqlDataSource");

        
SNOM1SqlDS.SelectParameters["lstPractice"].DefaultValue =  ddlLstPractice.SelectedValue;
        SNOM1SqlDS.SelectParameters["snomval1"].DefaultValue =
          (DropDownList1A.SelectedValue != String.Empty) ? DropDownList1A.SelectedValue :"";
        
SNOM1SqlDS.SelectParameters["snomval2"].DefaultValue =
          (DropDownList2A.SelectedValue != String.Empty) ? DropDownList2A.SelectedValue :"";
        
SNOM1SqlDS.SelectParameters["snomval3"].DefaultValue =
          (DropDownList3A.SelectedValue != String.Empty) ? DropDownList3A.SelectedValue :"";
                 SNOM1SqlDS.SelectParameters["snomval4"].DefaultValue =
            
(DropDownList4A.SelectedValue != String.Empty) ? DropDownList4A.SelectedValue :"";
        
SNOM1SqlDS.SelectParameters["pnomval"].DefaultValue = ddlPNOM.SelectedValue;
  }

I'm currently using Session variables in "OnDataBinding" so the selected values are "remembered" between postbacks.  I'm not sure if this is the proper way.  Should I be doing this differently?

protected void DropDownList1A_OnDataBinding(object sender, EventArgs e)
{
  DropDownList DropDownList1A = (DropDownList)sender;

  if (Session["DropDownList1A"] != null)
  {
    
if (Session["DropDownList1A"].ToString() != String.Empty)
          {
             string sVal = Session["DropDownList1A"].ToString();
             DropDownList1A.SelectedValue = sVal;
          }
        else
          { 
             string value = gvPracticeDetail.SelectedDataKey["sprac1"].ToString();
              if (DropDownList1A.Items.FindByText(value) != null)  DropDownList1A.SelectedValue = value;
     }


What can be causing this "jump" or loss of focus when the user mouse clicks into the DropDownList1B control (for example)?

Thank you,
Chris

        


                 
                     


      
     


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>