Thursday, April 5, 2012

Validate Date of Birth

protected void Page_Load(object sender, EventArgs e)
        {
              rvSearchDOB.MaximumValue = DateTime.Now.ToString("d");
        }

<asp:TextBox runat="server" ID="txtSearchDOB" />&nbsp;<asp:Image ImageUrl="~/Images/calender_btn.png"
                    runat="server" ID="imgCal" ImageAlign="AbsMiddle" />
                <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtSearchDOB"
                    Format="d" PopupButtonID="imgCal" />
                <asp:CompareValidator ErrorMessage="Invalid date format. Use (mm/dd/yyyy)" Display="None" ID="cvSearchDOB"
                    ControlToValidate="txtSearchDOB" Operator="DataTypeCheck" Type="Date" runat="server" ValidationGroup="grpSearchSubmit" />
                <ajaxtoolkit:ValidatorCalloutExtender ID="vcSearchDOB" runat="server" TargetControlID="cvSearchDOB"
                    PopupPosition="TopLeft" Enabled="True"  />
                <asp:RangeValidator ID="rvSearchDOB" runat="server" ControlToValidate="txtSearchDOB"
                    MinimumValue="1/1/1900" MaximumValue="1/1/2100" Type="Date" Text="Invalid Date"
                    Display="None" ValidationGroup="grpSearchSubmit" />
                <ajaxtoolkit:ValidatorCalloutExtender ID="vcretxtSearchDOB" runat="server" TargetControlID="rvSearchDOB"
                    PopupPosition="TopLeft" Enabled="True" />

Wednesday, April 4, 2012



With this simple jQuery function, you can notify a user if they’ve made any un-saved changes to a form field – and give them a chance to save or discard those changes. I was recently able to try this out on a work project and it is working beautifully.
I have a feeling THIS will come in very handy for a variety of projects.



var isDirty = false;
var msg = 'You haven't saved your changes.';

$(document).ready(function(){
   $(':input').change(function(){
      if(!isDirty){
         isDirty = true;
      }
   });

   window.onbeforeunload = function(){
      if(isDirty) {
         return msg;
      }
   };
});



Change the ValidatorCalloutExtender ErrorMessage

Change the ValidatorCalloutExtender ErrorMessage


sender.errormessage = "Please select atleast one Quintile.";
                        var cell = sender.ValidatorCalloutBehavior._errorMessageCell;
                        // cell is going to be null first time.                       
                        if (cell != null) {
                            cell.innerHTML = "Please select atleast one Quintile.";
                        }

Monday, April 2, 2012

Select-all checkbox Jquery for ASP.NET GridView,DataList,Repeater etc.

Scenario
1.On Parent check box Selecting, All - Child check boxes should be checked.
2.On Manually Selecting all child check boxes, parent should be checked.
3.Deselecting one of the child check box Parent should be deselected

Markup Code for Reapeter
same thing can be done using Gridview or DataList also.
I have used only cssclass for selecting appropriate control so you don't have to worry about what html parsing id's of checkboxes.


 <asp:Repeater ID="rpSections" runat="server">  
           <HeaderTemplate>  
             <table class="def_table" width="100%">  
               <tr>  
                 <th>  
                   <asp:Label runat="server" ID="lblQuestionnaireTypeHeader" />  
                 </th>  
                 <td align="left">  
                   <asp:CheckBox ID="cbCheckAll" runat="server" CssClass="chkHeader" />  
                 </td>  
               </tr>  
           </HeaderTemplate>  
           <ItemTemplate>  
             <tr>  
               <td>  
                 <%# DataBinder.Eval(Container.DataItem,"Section.SurveyName" ) %>  
               </td>  
               <td>  
                 <asp:CheckBox ID="chk" runat="server" CssClass="chkItem" />  
               </td>  
             </tr>  
           </ItemTemplate>  
           <FooterTemplate>  
             </table>  
           </FooterTemplate>  
         </asp:Repeater>  

Jquery code (don't forget to add jquery reference)

  <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.js" type="text/javascript"></script>