November 25, 2016

Javascript validation and useful methods

Perfect Calendar in textbox with some validation


<asp:TextBox ID="txtFromDate" CssClass="Textbox" runat="server" ValidationGroup="Report"
Width="120px" onkeyup="if(this.value != ''){this.value = '';confirm('Please select from calendar.');}return false;"></asp:TextBox>

 <asp:RequiredFieldValidator ID="rfvtxtFromDate" runat="server" ErrorMessage="Enter From Date"
                        ControlToValidate="txtFromDate" ValidationGroup="Report">*</asp:RequiredFieldValidator>

<cc1:CalendarExtender ID="ceFromDate" runat="server" TargetControlID="txtFromDate"
Format="dd/MM/yyyy"></cc1:CalendarExtender>

On Key Up event


function validateAplabeticValue(that) {
            var re = /[^a-z.\s]/gi;

            if (re.test(that.value)) {
                that.value = that.value.replace(re, '');
                alert('Enter only alphabetic value');
            }
        }

  <asp:TextBox ID="txtExtstakhld" runat="server" 
onkeyup="validateAplabeticValue(this);"
MaxLength="30" Width="300px"></asp:TextBox>

Check javascript enable or not


 <noscript>
        <div>
            You must enable javascript to continue.
        </div>
    </noscript>

if you are using old browser then run the below script
 <!--[if lt ie 9]>
<script type="text/javascript">
alert("You are using old IE version, Please upgrade to the latest");
         window.location="http://windows.microsoft.com/en-IN/internet-explorer/download-ie";
</script>
<![endif]-->


Allow Only Alphabets


var specialKeys = new Array();
specialKeys.push(0); //Tab for Firefox
specialKeys.push(8); //Backspace
specialKeys.push(9); //Tab
specialKeys.push(32); //Space
function onlyAlphabets(e, t) {
    try {
        if (window.event) {
            var charCode = window.event.keyCode;
        }
        else if (e) {
            var charCode = e.which;
        }
        else { return true; }
        if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
            return true;
        else {

            for (var num in specialKeys) {
                if (charCode == specialKeys[num])
                    return true;
            }
            return false;
        }
    }
    catch (err) {
        alert(err.Description);
    }
}


Allow Only Alphabets


function onlyAlphabetsNoSpace(e, t) {
    try {
        if (window.event) {
            var charCode = window.event.keyCode;
        }
        else if (e) {
            var charCode = e.which;
        }
        else { return true; }
        if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
            return true;
        else {
            for (var num in specialKeys) {
                if (specialKeys[num] == 32)
                    return false;
                if (charCode == specialKeys[num])
                    return true;
            }
            return false;
        }
    }
    catch (err) {
        alert(err.Description);
    }
}


<asp:TextBox runat="server" ID="txtidfirstname" MaxLength="12" CssClass="txt-box-full" 
onkeypress="return onlyAlphabetsNoSpace(event,this);" ondrop="return false;" onpaste="return false;" />


 function validateAplabeticValue(that) {
            var re = /[^a-z.\s]/gi;

            if (re.test(that.value)) {
                that.value = that.value.replace(re, '');
                alert('Enter only alphabetic value');
            }
        }

Allow alphanumeric


function IsAlphaNumeric(e) {

    var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
    var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
    if (ret) {
        return true;
    } else {
        for (var num in specialKeys) {
            if (keyCode == specialKeys[num])
                return true;
        }
        return false;
    }
}


Allow Decimal Number


function isNumberDecimalKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    } else {
        // If the number field already has . then don't allow to enter . again.
        if (evt.target.value.search(/\./) > -1 && charCode == 46) {
            return false;
        }
        return true;
    }
}


Allow Number


function isNumber(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    //if (charCode > 31 && (charCode < 48 || charCode > 57)) {
       
    //    return false;
    //}
    //return true;
    if (charCode > 47 && charCode < 58) {
        return true;
    } else {
        for (var num in specialKeys) {
            if (charCode == specialKeys[num])
                return true;
        }
        return false;
    }
}

Change the Value of other control


    function ddlPan() {
        var ddl = document.getElementById("<%=ddlPAN.ClientID%>");
        var SelVal = ddl.options[ddl.selectedIndex].value;
        if (SelVal == "N" || SelVal == "") {
            document.getElementById("<%=txtPANNumber.ClientID%>").value = "";
            document.getElementById("<%=txtPANNumber.ClientID%>").disabled = true;
        }
        else
            document.getElementById("<%=txtPANNumber.ClientID%>").disabled = false;
    }


    <asp:DropDownList runat="server" ID="ddlPAN" CssClass="dropdown-box-full" onchange="ddlPan()">

November 8, 2016

Common model popup for all the pages

we can use common model popup for all pages

Master Page Code snippet

 <cc1:ModalPopupExtender ID="mppopup" runat="server" BehaviorID="modalpopup" BackgroundCssClass="backgroundmodal"
            TargetControlID="btnpopup" CancelControlID="btnCancel" OkControlID="btnOkay"
            PopupControlID="panelmodal">
        </cc1:ModalPopupExtender>
        <asp:Button runat="server" ID="btnpopup" OnClick="btnpopup_Click" Text="PopUp" CssClass="hide" /><!--dummy button-->
        <asp:Panel ID="panelmodal" Style="display: none" CssClass="modal-dialog" runat="server">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" runat="server" id="myModalheader">Alert</h4>
                </div>
                <div class="modal-body">
                    <div class="alert-content">
                        <p runat="server" id="palertmessage">Hello, this is an alert</p>
                    </div>
                </div>
                <div class="modal-footer">
                    <asp:Button ID="btnOkay" runat="server" Text="Ok" CssClass="btn-small" UseSubmitBehavior="true" OnClientClick="javascript:skipLN();" />
                    <asp:Button ID="btnCancel" runat="server" Text="Can" CssClass="btn-small" UseSubmitBehavior="true" OnClientClick="javascript:skipLN();" />
                </div>
            </div>
        </asp:Panel>


class - find the control from master page and did the dynamic activity

public void CallModalPopup(MasterPage master, string RedirectPageName, string AlertBody, string AlertHeader = "Notification", string OKtext = "OK", string CanText = "CANCEL", bool ShowOk = true, bool showCancel = true, bool skipLN = true)
        {

            AjaxControlToolkit.ModalPopupExtender mp = (AjaxControlToolkit.ModalPopupExtender)master.FindControl("mppopup");

            System.Web.UI.HtmlControls.HtmlGenericControl body = (System.Web.UI.HtmlControls.HtmlGenericControl)master.FindControl("palertmessage");

            System.Web.UI.HtmlControls.HtmlGenericControl header = (System.Web.UI.HtmlControls.HtmlGenericControl)master.FindControl("myModalheader");

            Button okay = (Button)master.FindControl("panelmodal").FindControl("btnOkay");
            Button cancel = (Button)master.FindControl("panelmodal").FindControl("btnCancel");

            okay.OnClientClick = "";
            if (RedirectPageName != "")
                if (RedirectPageName.Contains("window.open"))
                    okay.OnClientClick = RedirectPageName;
                else if (skipLN)
                    okay.OnClientClick = "javascript:skipLN();window.location.href='" + RedirectPageName + "'";
                else
                {
                    okay.OnClientClick = "window.location.href='" + RedirectPageName + "'";
                    HttpContext.Current.Session["UserID"] = "ERROR";
                }
            okay.UseSubmitBehavior = true;
            okay.Text = OKtext;
            okay.Focus();
            cancel.Text = CanText;
   
            if (!showCancel)
                cancel.Attributes.Add("style", "display:none !important;");
            body.InnerText = AlertBody;
            header.InnerText = AlertHeader;

            mp.Show();
   
        }

call from Page

CallModalPopup(this.Master, "", "You can register interest for upto 3 interest areas and job roles", showCancel: false);

November 6, 2016

WWF -Project structure

PROJECT STRUCTURE CHANGED AS FRAMEWORK CHANGED







Part 1: Windows workflow foundation (WWF)

WWF is workflow Framework for Microsoft product.

WF Framework is compose of library,Execution Engine, Rules engine, a number of activities, a number of supporting runtime services.

WF contains graphical debugger.

The engine is designed in such a way that the developer has a free choice between building the workflow as code constructs or in a declarative fashion using XAML. 

Workflow: A workflow models a process as a set of activities applied to work in progress.

A workflow is constructed from a number of activities, and these activities are executed at runtime.

A number of built-in activities can be used for general-purpose work, 
and you can also create your own custom activities and plug these into the workflow as necessary


Workflow Runtime Engine: 
Every running workflow instance is created and maintained by an in-process runtime engine that is commonly referred to as the workflow runtime engine. 

There can be several workflow runtime engines within an application domain. 

Each instance of the runtime engine can support multiple workflow instances running concurrently.

Because a workflow is hosted in-process, a workflow can easily communicate with its host application.


Why should we use ?

  • Can see workflow visually. (More understandable way)
  • Separation between business logic and its implementation
  • No Need to Complie the workflow as it is xml. This flexibility even goes further and the engine allows for the runtime alteration of the executing workflow.
  • Due to it is library,it is flexible to included in application or site.

Activities : Activities run like tree structure.
Activities have two types of behavior
Runtime: specifies the actions upon execution.
Designtime: controls the appearance of the activity and its interaction while being displayed within the designer. 

Services
The workflow runtime engine uses many services when a workflow instance runs. Windows Workflow Foundation provides default implementations of the runtime services that meet the needs of many types of applications, such as a persistence service, which stores the execution details of a workflow instance in a SQL database. These service components are pluggable, which allows applications to provide these services in ways that are unique to their execution environment. Other types of services used by the runtime engine include scheduling services, transaction services, and tracking services.

Custom services can be created to extend the Windows Workflow Foundation platform by deriving from the base service classes. An example of this would be a persistence service that uses an XML file instead of a database for storage.

Persistency :

Windows Workflow Foundation simplifies the process of creating stateful, long-running, persistent workflow applications. The workflow runtime engine manages workflow execution and enables workflows to remain active for long periods of time and survive application restarts. This durability is a key tenet of Windows Workflow Foundation. It means that workflows can be unloaded from memory while awaiting input and serialized into a persistent store, such as a SQL database or XML file. Whenever the input is received, the workflow runtime engine loads the workflow state information back into memory and continues execution of the workflow.

Windows Workflow Foundation provides the SqlWorkflowPersistenceService that integrates well with Microsoft SQL Server to persist workflow information easily and efficiently. You can also create your own persistence service to store workflow state information anywhere you want by deriving from the WorkflowPersistenceService base class. 

Tracking
Tracking is the ability to specify and capture information about workflow instances and store that information as the instances execute. Windows Workflow Foundation provides the SqlTrackingService, which is a tracking service that uses a SQL database to store the collected tracking information. You can also write your own tracking service to collect and store this information in any format that your application requires.

When a new workflow is created, the tracking service requests a tracking channel to be associated with that workflow. All of the tracking information from the workflow is then sent to this tracking channel.

The tracking service can track three types of events:
  • Workflow instance events
  • Activity events
  • User events
You can configure the type and amount of information that your service wants to receive for a particular workflow instance or types of workflow by providing a tracking profile.

The tracking framework also provides the ability to extract information about activities or the workflow during an event. If a specific property or field in your activity or workflow needs to be tracked, you can provide this information in the extracts section of the tracking profile, and that information will be extracted during the specified event. 

Serialization
Workflows, activities, and rules can be serialized and deserialized. This enables you to persist them, use them in workflow markup files, and view their properties, fields, and events in a workflow designer.

Windows Workflow Foundation provides default serialization capabilities for standard activities, or you can create your own for custom activities. For example, with a custom activity serializer, you can decide which members are serialized and how they are serialized. This determines if those members are visible or hidden in a workflow designer