1
votes

I have this page structure

<MasterPage>
  <script type="text/javascript" src="../js/jquery.main.js"></script>
  <link rel="stylesheet" type="text/css" href="../css/all2.css" media="all" />
 <ContentPage>

  <updatePanel>
    <asp:DropDownList id="ddlCountry" runat="server" AutoPostBack="True"  CssClass="width_412" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" ></asp:DropDownList>
  </updatePanel>

 </ContentPage>
</MasterPage>

Now I need AutoPostBack="True" for binding states for selected country.

The problem is "am losing DropDownList designs when I put AutoPostBack="True""

without AutoPostBack:

enter image description here

with AutoPostBack:

enter image description here

I went inside jquery.main.js and found that designs for select were replaced dynamically

function replaceSelects() {
for(var q = 0; q < selects.length; q++) {
if (!selects[q].replaced && selects[q].offsetWidth && selects[q].className.indexOf("default") == -1){
    selects[q]._number = q;
    //create and build div structure
    var selectArea = document.createElement("div");
    var left = document.createElement("span");
    left.className = "left";
    selectArea.appendChild(left);
    var disabled = document.createElement("span");
    disabled.className = "disabled";
    selectArea.appendChild(disabled);
    selects[q]._disabled = disabled;
    var center = document.createElement("span");
    var button = document.createElement("a");
    var text = document.createTextNode(selectText);
    center.id = "mySelectText"+q;
    var stWidth = selects[q].offsetWidth;
    selectArea.style.width = stWidth + "px";
    if (selects[q].parentNode.className.indexOf("type2") != -1){
        button.href = "javascript:showOptions("+q+",true)";
    }else{button.href = "javascript:showOptions("+q+",false)";}
    button.className = "selectButton";
    selectArea.className = "selectArea";
    selectArea.className += " " + selects[q].className;
    selectArea.id = "sarea"+q;
    center.className = "center";
    center.appendChild(text);
    selectArea.appendChild(center);
    selectArea.appendChild(button);
    //hide the select field
    selects[q].className += " outtaHere";
    //insert select div
    selects[q].parentNode.insertBefore(selectArea, selects[q]);
    //build & place options div
    var optionsDiv = document.createElement("div");
    var optionsListParent = document.createElement("div");
    optionsListParent.className = "select-center";
    var optionsListParent2 = document.createElement("div");
    optionsListParent2.className = "select-center-right";
    var optionsList = document.createElement("ul");
    optionsDiv.innerHTML += "<div class='select-top'><div class='select-top-left'></div><div class='select-top-right'></div></div>";
    optionsListParent.appendChild(optionsListParent2);
    optionsListParent.appendChild(optionsList);
    optionsDiv.appendChild(optionsListParent);
    selects[q]._options = optionsList;
    optionsDiv.style.width = stWidth + "px";
    optionsDiv._parent = selectArea;
    optionsDiv.className = "optionsDivInvisible";
    optionsDiv.id = "optionsDiv"+q;
    populateSelectOptions(selects[q]);
    optionsDiv.innerHTML += "<div class='select-bottom'><div class='select-bottom-left'></div><div class='select-bottom-right'></div></div>";
    document.getElementsByTagName("body")[0].appendChild(optionsDiv);
    selects[q].replaced = true;
    }
all_selects = true;
  }
  }

I think the update panel gets postbacked on load,Please help me out.

1

1 Answers

0
votes

I went inside jquery.main.js and found that designs for select were replaced dynamically

I'm afraid UpdatePanel works by replacing all of the content inside of it. That's why your styling is getting destroyed.

If keeping the styling is important to you, you have two options:

  • Move to a more native AJAX solution. Ie, catch the change in JavaScript, then make an AJAX call to some web service or even static method in your page to do what you need to do.

  • See if there's a way to get jQuery to re-style you dropdown after every call from the UpdatePanel completes.

In all honesty, UpdatePanel was Microsoft's first attempt at some sort of Ajax library, and it wasn't exactly their best effort. Moving away from this wouldn't be the worst idea. I know that's not the quick answer you were looking for, though.