Avatar

Blog (pg. 15)

  • Published on
    The Silverlight client has some self imposed URL access restrictions, which may catch you out from time to time. The most common, cross domain calls, are easy to spot as when something doesn't work you will no doubt fire up fiddler and see the request for the cross domain policy file. This will remind you what you need to do ;) I haven't come across the need to implement cross scheme calls yet, but cross-zone calls have caught me out, as until you encounter it you might not even think it would be an issue. There is no error generated for a cross-zone call being blocked, there is also no traffic generated from Silverlight (so nothing in Fiddler), the call is blocked before any connection is attempted. So to the developer, your app loads and any calls to the services hosted 'cross zone' will not work, with no apparent reason. If this happens to you, you need to check your Internet Explorer settings (even for Firefox hosted Silverlight) to make sure that the client and the server are in the same zone. If they are not you can change your client/server URLs, where they are hosted or change the zone settings in IE (your system administrator may need to push a policy out to intranet users if you choose this option)
  • Published on
    Prior to version 4 of ASP.NET the GridView's EditIndex property was not automatically set when firing the 'RowEditing' event. It was up to the programmer to set this value before rebinding, if they wanted the row to go into edit mode i.e.:
    
    Private Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
             GridView1.EditIndex=e.NewEditIndex
             BindGrid()
    End Sub
    
    When the grid rebinds, it would now be in edit mode on the selected index. Sometimes you handle the RowEditing event and do something other than put the row into edit mode, such as showing a custom popup window as the editor. Previously this meant intentionally not adding the above line which meant when the grid was rebound it would not be in edit mode. ASP.NET 4 is now automatically setting the EditIndex property, which is affecting backward compatibility in converted projects. The only way to prevent the grid from now going into edit mode on a row is to set 'e.Cancel=True' in the 'RowEditing' event e.g.:
    
    Private Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
            'we only want the unique ID of the data in the row
            Dim primaryKey As Integer = CInt(GridView1.DataKeys(e.NewEditIndex).Value)
    
            'show a popup window to edit the data for this row
            popEditWindow.CurrentRecordId = primaryKey
            popEditWindow.DataBind()
    
            mpeEditPopup.Show()
            e.Cancel = True 'we now need to add this line to prevent the row from going into edit mode
    End Sub
    
    A quick search on Google shows that this problem has already been reported to Microsoft which can be tracked here.
  • Published on
    My blog is now back online after spending several months in a dormant state (thanks to Google switching off FTP publishing on Blogger!) Needless to say I have now stopped blogging with Blogger and switched to WordPress.
  • Published on
    The calendar extender that comes with the AJAX Control Toolkit has a bug in IE8 whereby the 'left/right' arrows to scroll through months do not work.

    This is caused by the fact that the 'title' div spans the full width of the control and so the links end up behind this div.

    To fix this problem, add the following line to your stylesheet:
    .ajax__calendar_title {width:150px; margin:auto; }
  • Published on
    ASP.NET includes a built in calendar control 'asp:Calendar' which is an easy way to display a calendar on your page. This is fully customisable in terms of look and feel and you can use this functionality to apply restrictions to the selectable dates. A lot times when building commercial websites the calendar week should only really apply to week days and not weekends. Although you should be checking this in your business logic layers, it is helpful to users if we do not let them submit invalid information. The following shows how you disable the weekend days by 'greying them out' (there is no reason why you could simply hide them altogether). Declare the calendar control:
    <asp:Calendar ID="calCollectionDate" runat="server" SelectionMode="Day" WeekendDayStyle-CssClass="disabledDay"></asp:Calendar>
    Use Javascript to find the 'disabledDay' items and remove the links:
    <script type="text/javascript" language="javascript">
    <!--
      var disabledDays=getElementsByClassName('disabledDay', '.*', document.getElementById('<%=calCollectionDate.ClientID %>'));
      for(var i=0;i<disabledDays.length;i++)
      {
        disabledDays[i].innerHTML="<span>"+disabledDays[i].innerHTML.replace(/\<a.*?\>(.*?)\<\/a\>/ig,'$1')+"</span>";
    
        disabledDays[i].style.color='#8e8e8e';
      }
    -->
    </script>
    This script relies on a third party script for 'getElementByClassName' which can be downloaded from www.robertnyman.com