Wednesday, September 26, 2012

reminder on validations in ajax mvc razor

 Order IS important and can stop the client side vlidation working if not in this order.
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>


        [Required]
        [StringLength(20, MinimumLength = 4)]
        [Display(Name = "User Name")]
        [RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed")]
        [ScaffoldColumn(false)]
        public string UserName { get; set; }

        [Required]
        [StringLength(18, MinimumLength = 0)]
        [Display(Name = "First Name")]
        public string FirstName { get; set; }
        [Required]
        [StringLength(18, MinimumLength = 0)]
        [Display(Name = "Last Name")]
        public string LastName { get; set; }

            <div class="editor-label">
                @Html.LabelFor(model => model.FirstName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.FirstName)
                @Html.ValidationMessageFor(model => model.FirstName)
            </div>
           
            <div class="editor-label">
                @Html.LabelFor(model => model.LastName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.LastName)
                @Html.ValidationMessageFor(model => model.LastName)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.UserName)
                @Html.ValidationMessageFor(model => model.UserName)
            </div>


All Active Directory Users 1000 user limit

Only 1000 of my AD entries were being returned by dsUsers,FindAll(), quick search after spending what seemed hours banging my head trying to debug where I could only access a small development DC with < 100 users...So deploy to prod server and output file appends with info, yeah the long way.
It was also only returning a portion of the properties within that 1000 too, 381 entries it told me didn't have an ipPhone field set, whereas Domain Users server tools told me that 99% were set...
Anyway, found that someone already had figured out to frig the Pagesize parameter, which for some reason got past the 1000 restriction.

                    // declare directory searcher
                    DirectorySearcher dsUsers = new DirectorySearcher(deRoot);

                    dsUsers.SearchScope = SearchScope.Subtree;
                    //OR the filter
                    dsUsers.Filter = "(|(objectCategory=person)(objectClass=user))";
                    dsUsers.PageSize = 1001;// ms limitation with shitty workaround

                    // define what properties you want to have loaded into your search results
                    dsUsers.PropertiesToLoad.Add("givenName");
                    dsUsers.PropertiesToLoad.Add("sn");
                    dsUsers.PropertiesToLoad.Add("samAccountName");
                    dsUsers.PropertiesToLoad.Add("ipPhone");
                    dsUsers.PropertiesToLoad.Add("telephoneNumber");
                    dsUsers.PropertiesToLoad.Add("mobile");
                    dsUsers.PropertiesToLoad.Add("department");
                    dsUsers.PropertiesToLoad.Add("l");

Tuesday, September 11, 2012

handy dynamic JQuery event handler


in View :-
grid2.Column(format: @<input type="button" onclick="mysub='@item.UserName'" value="Setup" name="Setup" id="Setup" />),

var mysub = "";

            $(function () {
                $("#Setup").live('click', function () {
                    alert(mysub);
                });
            });