Disable weekends for AjaxToolKit Calendar extender

October 19, 2010

AJAXTOOLKIT version 3.0.30512.0

It is possible to disable weekends/public holidays as per your need, using javascript

Following is the code to disable weekends

javascript to disable weekends

function DisableWeekends(sender, args)
{
     for(var i=0; i<sender._days.all.length; i++)
    {
              for(var j=0; j<6; j++)
             {
                    if(sender._days.all[i].id == “calendarValidToDate_day_”+j+”_0″)
                   {
                          sender._days.all[i].disabled = true;
                          sender._days.all[i].innerHTML = “<div>” +sender._days.all[i].innerText+ “</div>”;
                    }

                    if(sender._days.all[i].id == “calendarValidToDate_day_”+j+”_6″)
                   {
                            sender._days.all[i].disabled = true;
                            sender._days.all[i].innerHTML = “<div>” +sender._days.all[i].innerText+ “</div>”;
                   }
            }
     }
}

Calendar extender html

<asp:TextBox ID=”txtDate” Enabled=”true” runat=”server” Width=”200px”></asp:TextBox>
<asp:ImageButton runat=”server” ID=”imageValidToDate” SkinID =”calendarButton” />

 <AJAXControl:CalendarExtender ID =”calendarValidToDate” runat=”server” TargetControlID=”txtDate”
                           Format=”dd/MM/yyyy” PopupButtonID =”imageValidToDate” FirstDayOfWeek=”Default”
                           OnClientShown=”DisableWeekends”>
                        </AJAXControl:CalendarExtender>

==================================================================================

Cheers

Irfan Yar

irfanyar@gmail.com


modalpopupextender drag problem

November 20, 2009

I have seen quite a few people getting issues with dragging the modal popup extender. If you are having an issue that when you drag the modal popup extender, it doesnt stay at the position you leave but gets back to its orginal position as soon as you leave the mouse button, then here is the solution, just replace your body tag with this

<body style=”min-height:710px;”>


Validation of expression (asp.net regular expression) through custom javascript

May 13, 2009

You can validate asp.net regular expressions using your custom javascript

var stringToValidate = document.getElementById(“txtPasswordId”).value;
            var expression= /(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,})$/;
            if (!expression.test(stringToValidate)) {
                alert(“enter valid password”);
            }

 

 

similarly you can validate any other regular expression generated by your asp.net validation controls


Setting visibility of asp.net elements through java script

May 11, 2009

If you are trying to show/hide a div or any other element via JavaScript (Java Script) and it appears to work on some browsers and not on others then one of the possible causes of failure is that you might be setting its visibility and display to “visible” and “block” etc What you need to do is to set the display of the element like this

document.getElementById(‘id’).style.display = ; //empty string

this works for all browsers as far as my experience is concerned

happy hunting

cheers

Irfan Yar


Schema based intellisence to custom files (with extension other than .xml)

June 7, 2008

Schema based intellisence to custom files (with extension other than .xml)

 

At times we have some files with custom extensions, like I had to use an extension “.casl”, but I wanted to incorporate the intellisence based on a XSD schema file to that casl file. Just like we do attach a schema to xml files and we get the intellisence available in the xml file. To achieve this we need to do the following.

 

1.       Locate the VS.net installation directory (e.g I have VS.net 2008 installed at C:\program files\Microsoft Visual Studio 9.0)

2.       You would be able to see a folder named “xml” and inside that folder you will see a folder named “schema” (on my system I can browse to the following path to get inside the schema folder C:\program files\Microsoft Visual Studio 9.0\Xml\Schemas)

3.       Inside “schema” folder you will find a configuration file named “catalog.xml”

4.       Open “catalog.xml” in the VS.net and add the following association tag (<Association extension=casl schema=c:/CaslSchema.xsd condition=*“>) just save this file and open the file with casl extension and you will be able to use the intellisence feature

 

Please note that you must place the custom schema at the path you specify inside the schema attribute (schema=c:/CaslSchema.xsd) in the above example I have placed it at C:/

 

 

To achieve this programmatically please try the following code

 

Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@”Software\Microsoft\VisualStudio\9.0″, true);

            string installationDirectoryPath = rk.GetValue(“InstallDir”).ToString();

            installationDirectoryPath = installationDirectoryPath.Replace(“\\Common7\\IDE\\”, “”);

            string configurationFilePath = installationDirectoryPath + “\\Xml\\Schemas\\catalog.xml”;

 

 

            System.IO.StreamReader sr = new StreamReader(new FileStream(configurationFilePath,System.IO.FileMode.Open,System.IO.FileAccess.ReadWrite));

 

            string fileContents = sr.ReadToEnd();

 

            sr.Close();

 

            XmlDocument xmlDoc = new XmlDocument();

 

            xmlDoc.LoadXml(fileContents);

 

 

            XmlNode node = xmlDoc.LastChild;

 

            bool associationExisits = false;

            foreach (XmlNode childNode in node.ChildNodes)

            {

                if (childNode.Attributes["extension"] != null)

                {

                    if (childNode.Attributes["extension"].Value.ToLower() == “casl”)

                    {

                        associationExisits = true;

                        break;

                    }

                }

            }

 

            if (!associationExisits)

            {

 

                XmlNode lastAssociationChild = node.LastChild;

                XmlNode newNode = lastAssociationChild.Clone();

 

                newNode.Attributes["extension"].Value = “casl”;

                newNode.Attributes["schema"].Value = @”C:\CamlSchema.xsd”;

                newNode.Attributes["condition"].Value = “*”;

 

                node.AppendChild(newNode);

 

 

                xmlDoc.LoadXml(“<SchemaCatalog  xmlns=\”http://schemas.microsoft.com/xsd/catalog\”>” + node.InnerXml + “</SchemaCatalog>”);

 

                StreamWriter writer = new StreamWriter(new FileStream(configurationFilePath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite));

 

                writer.Flush();

 

                writer.Write(xmlDoc.InnerXml);

 

                writer.Close();

            }

 

     

if there is any issue in this, please feel free to contact me at irfanyar@gmail.com

Cheers

Irfan Yar

 

 


locate the installation directory of visual studio .net (or any other installed software)

June 7, 2008

Get installation directory path

I have seen people trying to locate the installation directory of visual studio .net (or any other installed software). Microsoft windows register the installation path of VS.net in the registry. To get the installation path you can request the registry for this information. Following is the code snippet for doing this

 

Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@”Software\Microsoft\VisualStudio\9.0″, true);

            string installationDirectoryPath = regKey.GetValue(“InstallDir”).ToString();

 

 

if there is any issue in this, please feel free to contact me at irfanyar@gmail.com

 

Cheers

Irfan Yar


Custom lookup control for MSCRM 3.0

January 23, 2008

I have often seen people messing up with the lookup in their custom add ons to MSCRM 3.0

I made a custom lookup control for the same problem. its really simple and working perfectly fine for all entities

it has total 5 parts that you need to look for

1.       ascx (lookup control ) file

2.       javascript3.      Codebehind (.cs) file

4.      Style sheet

5.      Page on which lookup control resides

  let me explain all of them in order

1. ASCX (look and feel of lookup)

<%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”usrCtlLookUp.ascx.cs” Inherits=”usercontrols_usrCtlLookUp” %><table runat=”server” id=”tblMain” width=”84%” cellpadding=”0″ cellspacing=”0″ border=”0″>
<
tr>
<
td>
<
div class=”lookup”  id=”LookupText” runat=”server”></div>
</
td>
<
td style=”width:2px”></td>
<
td style=”width:21″>
<
img alt=”look up” src=”../images/lookup.gif” runat=”server” id=”imgLookup”/>
</
td>
</
tr>
</
table><input type=”hidden” runat=”server” id=”hdnEntityId” />
<
input type=”hidden” runat=”server” id=”hdnEntityName” />

2. Javascript file

// JScript Filefunction LookupArgsClass(){this.items = null;}function SetRegardingValues(entityCode,divId,hdnId){

var serverURL = document.getElementById(“hdnServerName”).value;var sPath= serverURL + ‘/_controls/lookup/lookupsingle.aspx?class=BasicOwner&objecttypes=’+entityCode+‘&browse=0&DefaultType=0′ var left = (screen.width/4);var top = (screen.height/5); if(entityCode == “1″ || entityCode == “2″ || entityCode == “10012″){//sPath= serverURL + ‘/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=1&browse=0&DefaultType=0′ sPath= serverURL + ‘/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=’+entityCode+‘&browse=0&DefaultType=0′ }

else if(entityCode == 8){sPath= serverURL + ‘/_controls/lookup/lookupsingle.aspx?class=BasicOwner&objecttypes=8&browse=0&DefaultType=0′ }var args = new LookupArgsClass(); args.items = document.getElementsByTagName(“SPAN”);var sCustomWinParams = “dialogWidth:600px0px;dialogHeight:488px;dialogLeft=”+left+“px;dialogTop=”+top+“px;help:0;status:1;scroll:0;center:1;resizable:yes;”var objlookup = window.showModalDialog(sPath,args,sCustomWinParams); if(objlookup != null){document.getElementById(hdnId.id).value = objlookup.items[0].id;document.getElementById(divId.id).innerHTML =

“  <a href=’#'>” + objlookup.items[0].name + “</a>”; }}function OpenUserEditDialogue(entityCode,divId,hdnId){

if(document.getElementById(hdnId.id).value == “”){return false;}var serverURL = document.getElementById(“hdnServerName”).value; var left = (screen.width/4);var top = (screen.height/5);var sPath= serverURL+ “/sfa/accts/edit.aspx?id=” + document.getElementById(hdnId.id).value;var sCustomWinParams = “dialogWidth:930px0px;dialogHeight:675px;dialogLeft=”+left+“px;dialogTop=”+top+“px;help:0;status:1;scroll:0;center:1;resizable:yes;”if(entityCode == “10001″){sPath= serverURL + ‘/_controls/lookup/lookupsingle.aspx?class=BasicOwner&objecttypes=’+entityCode+‘&browse=0&DefaultType=0′sCustomWinParams = “dialogWidth:600px0px;dialogHeight:488px;dialogLeft=”+left+“px;dialogTop=”+top+“px;help:0;status:1;scroll:0;center:1;resizable:yes;”

}if(entityCode == “8″){sPath= serverURL + ‘/_controls/lookup/lookupsingle.aspx?class=BasicOwner&objecttypes=8&browse=0&DefaultType=0′sCustomWinParams = “dialogWidth:831px0px;dialogHeight:641px;dialogLeft=”+left+“px;dialogTop=”+top+“px;help:0;status:1;scroll:0;center:1;resizable:yes;”

}else if(entityCode == “10012″){spath = serverURL + “_controls/lookup/lookupsingle.aspx?class=null&objecttypes=10012&browse=0&DefaultType=0″sCustomWinParams = “dialogWidth:1012px;dialogHeight:642px;dialogLeft=”+left+“px;dialogTop=”+top+“px;help:0;status:1;scroll:0;center:1;resizable:yes;”

}else if(entityCode == “2″){spath = serverURL +

“_controls/lookup/lookupsingle.aspx?class=null&objecttypes=2&browse=0&DefaultType=0″ }var args = new LookupArgsClass(); var objlookup = window.showModalDialog(sPath,args,sCustomWinParams);if(objlookup != null){document.getElementById(hdnId.id).value = objlookup.items[0].id;document.getElementById(divId.id).innerHTML = “  <a href=’#'>” + objlookup.items[0].name + “</a>”;}}

function CloseWindow(){window.close();return false;}

function ChangeStyle(divId,mouseOver){if(mouseOver){document.getElementById(divId.id).className = “lookupHover”;}else

{document.getElementById(divId.id).className = “lookup”;}}3. CodeBehind file

using System;using System.Data;using System.Configuration;using System.Collections;

using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Reflection;using CRMUtils.CrmSdk;

using CRMBusinessEntities;using CRMBusinessEntities.Operations;public partial class usercontrols_usrCtlLookUp : System.Web.UI.UserControl,IWebUserControl{public void LoadUserControl(Guid id){

if (id == Guid.Empty){id = new Guid(LookupEntityID);}else {LookupEntityID = id.ToString();}

string name = string.Empty;if(LookupEntityName.Equals(EntityName.account.ToString())){CRMAccount objAccount = new CRMAccount();account accountBe = (account)objAccount.GetAccountById(id,

new string[] { “accountid”, “name” });name = accountBe.name;}else if (LookupEntityName.Equals(EntityName.systemuser.ToString())){CRMUser objSystemUser = new CRMUser();systemuser systemuserBe = (systemuser)objSystemUser.GetSystemUserById(id, new string[] { “systemuserid”, “fullname” });name = systemuserBe.fullname;}else if (LookupEntityName.Equals(EntityName.new_hotel.ToString())){CRMHotel objHotel =

new CRMHotel();new_hotel hotelBe = (new_hotel)objHotel.GetHotelByHotelID(id, new string[] { “new_hotelid”, “new_hotelname” });name = hotelBe.new_hotelname;}

else if (LookupEntityName.Equals(EntityName.contact.ToString())){CRMContact objContact = new CRMContact();contact contactBe = (contact)objContact.GetContactById(id, new string[] { “contactid”, “fullname” });name = contactBe.fullname;}this.LookupText.InnerHtml = “  <a href=’#'>” + name + “</a>”;}

public void UpdateUserControl(){}protected void Page_Load(object sender, EventArgs e){CRMMetaData metaData = new CRMMetaData();this.imgLookup.Attributes.Add(“onclick”, “return SetRegardingValues(“ + metaData.GetEnityTypeCode(LookupEntityName) + “,” + this.LookupText.ClientID.ToString() + “,” + this.hdnEntityId.ClientID.ToString() + “);”);

this.LookupText.Attributes.Add(“onclick”, “return OpenUserEditDialogue(“ + metaData.GetEnityTypeCode(LookupEntityName) + “,” + this.LookupText.ClientID.ToString() + “,” + this.hdnEntityId.ClientID.ToString() + “);”);this.LookupText.Attributes.Add(“onmouseover”, “return ChangeStyle(“+ this.LookupText.ClientID.ToString() + “,true);”);this.LookupText.Attributes.Add(“onmouseover”, “return ChangeStyle(“ + this.LookupText.ClientID.ToString() + “,false);”); }public string LookupEntityID{get {return hdnEntityId.Value;}set

{hdnEntityId.Value = value;if (value == string.Empty){LookupText.InnerHtml = “”;}}}

public string LookupEntityName{get

{return hdnEntityName.Value;}set{hdnEntityName.Value = value;}}}

 4. CSS File (style sheet)

.lookup{    

  border-right: #7b9ebd 1px solid;       border-top: #7b9ebd 1px solid;       border-left: #7b9ebd 1px solid;       width: 97%;       border-bottom: #7b9ebd 1px solid;       height: 18px;      background-color:White;           

} 

.lookupHover{ 

     border-right: #7b9ebd 1px solid;       border-top: #7b9ebd 1px solid;       border-left: #7b9ebd 1px solid;       width: 97%;       border-bottom: #7b9ebd 1px solid;       height: 18px;      background-color:#ADC3E7;
}

 

5. Page or control (on which lookup control resides) 

protected void Page_Load(object sender, EventArgs e) 

   {

//just set the entity name for the lookup control       

 uclookUpControl.LookupEntityName = EntityName.account.ToString(); 

   } 

/*call the following function from anywhere in the container control (e.g on which you have draged and dropd the lookup control) to get the entity name populated, do not pass guid.Empty, but pass the entity ID here so that it could load the entity name, if you pass it empty, then you have to set the “LookupEntityID” property of the lookup control to the entity ID you want it to populate with */ 

uclookUpControl.LoadUserControl(Guid.Empty); 

 ======================================================================

 if you feel anything unclear, you can always send me an email at irfanyar@gmail.com 

===========================================================

 

  


Follow

Get every new post delivered to your Inbox.