DevExpress ASPxDropDownEdit loses text on postback

29 10 2009

So I’ve been trying to implement a devexpress multi-select drop down list box, and all is well except whenever you post back to the server – when the server returns the response to the browser, for some reason the text within the combo box gets cleared.  I’m not sure if it’s something I am doing incorrectly with the JS, or the set up of the devexpress control but either way – I decided to work around it, here’s the end result (a fully functional multi-select drop down which persists the text value cross postback).

The key is creating a hidden field, and storing the text value (when updated on the client side) into it, then on pageload, reset the value back into the text field so that when the postback returns, we refresh it with the value we posted to the server.  I’m still unsure as to why it’s losing its state, but this fixes it anyway.  Oh – and I’ve added in a ‘clear all’ function as well which wasn’t part of the original devexpress examples.  Enjoy!

NOTE:  When you enable auto postback on the checkboxes, you’ll run into some timing issues in the JS, I couldn’t solve this, so for now, no autopostback on the checkboxes, sorry!

      <asp:HiddenField runat=”server” ID=”multiChildText” />
       
     <script type=”text/javascript”>
         var textSeparator = “;”;
         function OnListBoxSelectionChanged(listBox, args) {        
             UpdateText();
         }
         function ClearAll() {
             checkListBox.UnselectAll();
             UpdateText();
         }
         function UpdateText() {
             var selectedItems = checkListBox.GetSelectedItems();
             var txt = GetSelectedItemsText(selectedItems);
             checkComboBox.SetText(txt);

             // Now, also set the hidden field!
             document.getElementById(“<%= multiChildText.ClientID %>”).value = checkComboBox.GetText();
         }
         function SynchronizeListBoxValues(dropDown, args) {
             UpdateText();  // for remove non-existing texts
         }
         function GetSelectedItemsText(items) {
             var texts = [];
             for (var i = 0; i < items.length; i++)
                 texts.push(items[i].text);
             return texts.join(textSeparator);
         }
         function GetValuesByTexts(texts) {
             var actualValues = [];
             var value = “”;
             for (var i = 0; i < texts.length; i++) {
                 value = GetValueByText(texts[i]);
                 if (value != null)
                     actualValues.push(value);
             }
             return actualValues;
         }
         function GetValueByText(text) {
             var text = Trim(text).toUpperCase();
             for (var i = 0; i < checkListBox.GetItemCount(); i++)
                 if (checkListBox.GetItem(i).text.toUpperCase() == text)
                 return checkListBox.GetItem(i).value;
             return null;
         }
         function Trim(str) {
             return str.replace(/\s*((\S+\s*)*)/, “$1″).replace(/((\s*\S+)*)\s*/, “$1″);
         }

         function pageLoad() {
             //setTimeout(‘UpdateText();’, 1200); hmmm :)
             checkComboBox.SetText(document.getElementById(“<%= multiChildText.ClientID %>”).value);
         }
    </script>

    <dxe:ASPxDropDownEdit ClientInstanceName=”checkComboBox” ID=”MultiChildren” SkinID=”CheckComboBox” runat=”server” CssClass=”child-multi-selection” EnableAnimation=”false”>
        <DropDownWindowTemplate>
            <dxe:ASPxListBox ID=”MultiChildrenList” ClientInstanceName=”checkListBox” SelectionMode=”CheckColumn”
                runat=”server” SkinID=”CheckComboBoxListBox” CssClass=”child-multi-select-list” AutoPostBack=”false”>

                <ClientSideEvents SelectedIndexChanged=”OnListBoxSelectionChanged” />
            </dxe:ASPxListBox>
            <table>
                <tr>
                <td >
                     <dxe:ASPxButton ID=”ClearAllButton” AutoPostBack=”False” runat=”server” Text=”Clear All”>
                            <ClientSideEvents Click=”function(s, e){ ClearAll(); }” />
                        </dxe:ASPxButton>
                    </td>
                    <td align=”right”>
                        <dxe:ASPxButton ID=”ASPxButton1″ AutoPostBack=”False” runat=”server” Text=”Close”>
                            <ClientSideEvents Click=”function(s, e){ checkComboBox.HideDropDown(); }” />
                        </dxe:ASPxButton>
                    </td>
                </tr>
            </table>
        </DropDownWindowTemplate>
        <ClientSideEvents TextChanged=”SynchronizeListBoxValues” DropDown=”SynchronizeListBoxValues” />
    </dxe:ASPxDropDownEdit>





Get every second element in an IEnumerable in C#

21 10 2009

var everySecondElement = myList.Where((p,d) => { return ((d % 2) < 1); });





Developed turned manager? Manager in general? READ THIS

5 09 2009

@mossyblog sent through a link to this article about management techniques, and I found it extremely insightful, and was able to relate to so many different areas and management styles I have seen over the years.  This will definitely make me a better manager when the time comes:

http://www.smashingmagazine.com/2009/09/03/professional-team-management-tips-for-creative-folks/

Read the whole thing :)





Using the Umbraco runway DropDownNavigation macro in your own masterpage.

31 08 2009

So you’ve tried taking the DropDownNavigation macro, inserted it into your own masterpage but it doesn’t work.  The Menu shows up expanded with no styling or javascript being applied.

The only fix I could come up with for this is to first ensure your <head> tag has a runat=”server” attribute, secondly, include the following script at the bottom of your masterpage/template:

 <script type=”text/javascript”>
        $(function() {
            $(‘#dropdownNavigation’).droppy({ speed: 10 });
        });
</script>

droppy.js will now load, the CSS will be applied (dropdownnavigation.css) and all will be well.

Remember to insert the menu via:

 <umbraco:Macro Alias=”RunwayDropdownNavigation” runat=”server” />

Also, make sure that you have a <title> element defined in your <head> element.

Someone else with this issue here: http://our.umbraco.org/forum/getting-started/questions-about-runway-and-modules/3425-Using-Runway-DropDownNavigation-with-other-pages





SharePoint 2010 Client Object Model

19 08 2009

This came through on twitter via @jthake before:
http://www.chakkaradeep.com/post/2009/08/19/SharePoint-2010-Introducing-the-Client-Object-Model.aspx

I’m really excited about this one – finally we can start using a standardised object model and not have to worry about how weather we are going to use web services, or the local object model.  The most powerful/exciting part to all of this (in my opinion) is the ability to talk with the object model directly via your Silverlight applications – this makes it so much easier/compelling to build rich, user focused, high-reach applications on top of the SharePoint platform.

I can see a lot of potential with this – it would be quite easy to build a silverlight front-end for SharePoint by interacting directly with the client object model – if you were to do this using web services it would take forever!  Your other alternative I guess would have been to write some RIA services wrapping the OM and call them out of silverlight – but I guess now we don’t have to :)

Nice!





Support SharePoint 2010 with this new Twibbon!

19 08 2009

Well, I was over at Twibbon.com and thought I’d see if anyone had made a SharePoint 2010 icon, and sure enough William Cornwill had uploaded one (Nice one Will!). 

I wasn’t a big fan of the one Will uploaded, so I decided to try create one that didn’t look like a minature dress, or a duck that had just been ran over by a semi-trailor.

http://twibbon.com/join/SharePoint-2010-2

Creating a twibbon was ALOT harder than I first expected – due to the small size of the icon, it’s really hard to get clarity in the image.  I decided to white-strip the logo and place the text and MS2010 logo on the right, unfortuantely it covers a fair bit of your twitter icon – does anyone else have any better suggestions?  I wan’t to make it look nicer :(

Happy sharepointing!





Report Parameter Missing a Value

25 06 2009

If you are getting this error when using the SQL Server 2005 Web Forms Report Viewer (ASP.NET) it’s probably because you are using an old version of the report viewer.

Please install the 2005 SP1 version of the Report Viewer Distributable.

http://www.microsoft.com/downloads/details.aspx?familyid=E7D661BA-DC95-4EB3-8916-3E31340DDC2C&displaylang=en

Either that, of your call to rv.ServerReport.SetParameters() doesn’t have a valid report parameter.





Some good JQuery examples

17 06 2009

http://www.slideshare.net/dbert721/introduction-to-jquery-presentation





Forms Services – Schema validation failed for some data items in the form

8 05 2009

If you’re performing data migration, and moving XML nodes around (or generating the form from template.xml or something similar), it will leave xsi:nil=”true” attributes on the nodes.

Then, if you copy these nodes and intend on filling them with information, you need to either remove the xsi:nil attributes, or set them to false.  How do you do it?  It’s quite simple:

XPathNavigator nilField = DOM.SelectSingleNode(“/my:myFields/my:myNilField“);
if (nilField.MoveToAttribute(“nil”,  “http://www.w3.org/2001/XMLSchema-instance”))
    nilField.DeleteSelf();

This essentially selects the field in question, positions the XPathNavigator to point at the nil attribute, and if it exists (or the pointer move succeeds) it will remove the attribute at its current position (aka, itll delete the nil attribute).

This tends to happen with DateTime fields in your schema (more often than not).

Matt





MOSS & WSS SP2 released

28 04 2009