Sumedh Meshram

A Personal Blog


Select distinct from generic list using linq

If you have a generic list which has a multiple data like

ID  FirstName  LastName  City  State Zip

1   ABC           Z              PN   LA     25341

2   XYZ           R              UI   TG     56742

1   ABC           W             PN   LA     25341

3   UHY           R             HJ    UH    34256

3   UHY           J              HJ    UH    34256 

Now if you want to get select distinct rows on based on ID, then through Linq this can be done easily as :


var unique =
    from w in genericList
    group w by w.ID
    into g
        select g.FirstOrDefault();


This will be useful where we have the generic list with duplicate data or data with duplicate IDs.



Finding all controls in an ASP.NET Page

This can be done through enumerating all the controls in the control hierarchy:

Add a method in a common class


/// <summary>
/// Find the Controls inside a Page
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
public static IEnumerable<Control> EnumerateControlsRecursive(Control parent)
     foreach (Control child in parent.Controls)
            yield return child;
            foreach (Control descendant in EnumerateControlsRecursive(child))
               yield return descendant;


Implement this method like this on the PreRender event of a page :


 protected override void OnPreRender(EventArgs e)
      foreach (var control in RecursiveHelper.EnumerateControlsRecursive(this))
        if (control is TextBox)
           SetTextBoxStyle(control as TextBox);

        if (control is RegularExpressionValidator)
           SetTextBoxEnterValidation(control as RegularExpressionValidator);


Then add your method seperately for assigning the common attributes to each control.


 private static void SetTextBoxStyle(TextBox textBox)
       textBox.CssClass = "emptyMessageStyle";



Hope this will help.


Ajax .Net 3.5 Control Toolkit MaskedEditExtender Default to PM

MaskedEditExtender can be set to default to PM.

I modified the code from

to this


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SoluTest_Mask._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <script type="text/javascript">
        //Set the default text to "PM"
        var mee;
        function pageLoad() {
            //Please use your MaskedEditExtender's id or behaviorId.
            mee = $find("MaskedEditExtender3");
            //The target textbox control
            var e = mee.get_element();
            //Remove the focus event handler
            if (mee._focusHandler) {
                $removeHandler(e, "focus", mee._focusHandler);
            //Add a new focus event handler which inherits from the old one.
            mee._focusHandler = Function.createDelegate(mee, newFocus);
            $addHandler(e, "focus", mee._focusHandler);
        function newFocus() {
            if ((mee._MaskType == AjaxControlToolkit.MaskedEditType.Time || mee._MaskType == AjaxControlToolkit.MaskedEditType.DateTime) && mee.get_CultureAMPMPlaceholder() != "" && mee._getClearMask() == "") {
                if (mee._AcceptAmPm) {
                    //The original code of default AM/PM text in function _onFocus() is:
                   mee.setSelectionRange(0, 0);
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <strong>Enter Time (format: <em>99:99:99</em>):</strong>
        <br />
        <asp:TextBox ID="TextBox3" runat="server" Width="130px" Height="16px" />
        <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender3" runat="server" TargetControlID="TextBox3"
            Mask="99:99:99" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus"
            OnInvalidCssClass="MaskedEditError" MaskType="Time" AcceptAMPM="True" ErrorTooltipEnabled="True" />
        <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator3" runat="server" ControlExtender="MaskedEditExtender3"
            ControlToValidate="TextBox3" IsValidEmpty="False" EmptyValueMessage="Time is required"
            InvalidValueMessage="Time is invalid" Display="Dynamic" TooltipMessage="Input a time"
            EmptyValueBlurredText="*" InvalidValueBlurredMessage="*" />
        <br />
        <em><span style="font-size: 8pt">Tip: Type 'A' or 'P' to switch AM/PM</span></em>

Hope this Help



Cheap MLB Jerseys maillot de foot pas cher