Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Friday, March 6, 2015

How to change the Date Format of an inline DatePicker in jQuery Editable DataTables

I've been working on a .Net MVC project that uses an older version of jQuery Datatables. The work involved upgrading a datatable to be editable. Using this CodeProject article I successfully upgraded the DataTable with DataTables Editable.

DataTables editable allows for non-standard inline input types, one of which is a datepicker, described here, which uses jeditable-datepicker. One problem I faced was setting the format of the datepicker to EU format dd/mm/yy rather than the default US format mm/dd/yy.

After exhausting lots of methods of conversion both client side and server side, I finally stumbled upon the github page for jeditable-datpicker which lists format as one of the usage options. A simple option yes, but lack of detailed documentation for DataTables Editable caused me to go searching and experimenting for longer than I should have needed to. Hopefully this post will save someone else that time :-)

For posterity, the code below shows how to set the format option of a datepicker in an editable datatable:


...
"aoColumns": [
{  type:   'datepicker',
    sSuccessResponse: "IGNORE",
    datepicker: {
        dateFormat: 'dd/mm/yy'
    }
},
]
...


SOURCE LINKS:

CodeProject - ASP.NET MVC Editable Table (jQuery DataTables and ASP.NET MVC integration - Part II)

jQuery DataTables Usage Reference

GitHub - jEditable Datepicker

Wednesday, March 12, 2014

Visual Studio Debugging - Waiting For Localhost

PROBLEM:
When debugging an ASP.Net application in Visual Studio 2010, launching the inbuilt webserver in Firefox is extremely slow and may eventually time out.

CAUSE:
An IPv6 DNS problem with Firefox

SOLUTION:
Load the about:config screen in Firefox and set network.dns.disableIPv6 to true.


SOURCE:
http://stackoverflow.com/questions/6405121/how-to-figure-out-why-my-local-host-site-takes-so-long-to-load

Thursday, February 20, 2014

LoadUserProfile Function Error - Returning Value 1314

I came across this error while trying to Debug-Run a C# ASP.Net web app in Visual Studio 2010.

PROBLEM:
Calling LoadUserProfile returns an error value of 1314 while attempting to impersonate a windows user programmatically.


CAUSE:
Permissions, or rather:
"The calling processes must have SE_RESTORE_NAME and SE_BACKUP_NAME privileges" - http://msdn.microsoft.com/en-us/library/bb762281%28VS.85%29.aspx


SOLUTION
Run Visual Studio as Administrator.
A simple one after about an hour of trouble shooting, right-click on the VS icon and choose Run As Administrator.

SOURCE
http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/b9ea2a0e-5a0e-4e07-92e2-4c7e1f2c5496/loaduserprofile-returning-value-1314-errorprivilegenotheld?forum=windowssecurity


Monday, April 11, 2011

ASP.NET CheckboxList Validation with RequiredFieldValidator

In order to use a RequiredFieldValidator with a CheckBoxList, you need to define your own CheckBoxList class that inherits from CheckBoxList , but also implements a ValidationPropertyAttribute  method:


    [ValidationPropertyAttribute("ValidateableProperty")]
    public class ValidateableCheckBoxList : CheckBoxList
    {
 
        public string ValidateableProperty
        {
            get
            {
                string result = "";
                int count = 0;
                foreach (ListItem item in this.Items)
                {
                    if (item.Selected)
                    {
                        count++;
                    }
 
                }
                if (count > 0)
                {
                    result = count.ToString();
                }
                else
                {
                    result = "";
                }
                return result;
            }
        }
    }


You can then create a ValidateableCheckBoxList and point a required validator's controlToValidate attribute to it.

SOURCE:
http://pedroliska.wordpress.com/2009/08/13/getting-an-asp-net-checkboxlist-to-work-with-a-requiredfieldvalidator/

Wednesday, March 23, 2011

ASP.NET Membership User Locked

PROBLEM:
ASP.NET membership user password cannot be reset

CAUSE:
User account is locked (caused by incorrect password being entered numerous times)

SOLUTION:
Unlock user account using SQL query:

DECLARE     @return_value int

EXEC  @return_value = [dbo].[aspnet_Membership_UnlockUser]
            @ApplicationName = N‘applicationName’,
            @UserName = N‘user’
SELECT      ‘Return Value’ = @return_value
GO


SOURCE:
http://codinglifestyle.wordpress.com/2010/02/13/unlock-user-via-database-query-asp-net-membership/

Thursday, March 3, 2011

ASP.NET AJAX JS Error - Sys.InvalidOperationException: Two components with the same id 'x' can't be added to the application.

ERROR:
Sys.InvalidOperationException: Two components with the same id 'x' can't be added to the application.

CAUSE:
ASP.NET Ajax Control Toolkit generated javascript code is in debug mode, which has extra checks that throw this error.

SOLUTION:
Set debug="false" in the web.config.

Monday, February 7, 2011

ASP.NET LINQ Union Distinct not working

Using Union(....).Distinct() not producing a distinct list when unioning a list of complex objects.

CAUSE:
Union() and Distinct() don't know which member of the object to use in their comparisons.

SOLUTION:
1. - IEqualityComparer needs to be defined to specify what fields of the object to compare:

public class MyComplexObjectComparer : IEqualityComparer
{
public bool Equals(complexObject a, complexObject b)
{
return a.Id == b.Id;
}

public int GetHashCode(complexObject obj)
{
return obj.Id.GetHashCode();
}
}

2. - Pass this comparer into the Union:

.Union(lockedout, new MyComplexObjectComparer()).Distinct;


SOURCE:
http://blog.dreamlabsolutions.com/post/2009/06/23/Enumerable-Except-TSource-and-IEqualityComparer-a-little-help.aspx

Tuesday, September 14, 2010

Using LINQ to get a Distinct List

First, create a type comparer:

    public class ItemComparer : IEqualityComparer<Item>
    {
        #region IEqualityComparer<Item> Members
 
        public bool Equals(Item x, Item y)
        {
            return x.ItemID == y.ItemID;
        }
 
        public int GetHashCode(Item obj)
        {
            return obj.ItemID.GetHashCode();
        }
        #endregion
    } 


Then, use it as follows on a List items:

    IEnumerable<Item> distinctItems = 
          items.Distinct(new ItemComparer());
    items = distinctItems.ToList();

Wednesday, May 26, 2010

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

Came across this error with a SQL Server 2005 sproc, being called via a Visual Studio 2008 xsd table adapter.


Solution: 
Check your data adapter tables, the sproc was missing 2 columns that the datatable was expecting in the results:


http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/27aec612-5ca4-41ba-80d6-0204893fdcd1/