Wednesday, December 25, 2013

Are you aware of .importance DOM while using .insertBefore in JS ?


In javascript .insertBefore is used to Insert every element in the set of matched elements before the target.
As same as .insertAfter function Insert every element in the set of matched elements after the target.

As in the following example I have used it for the moving selected items up/down in the list box. In each up/down arrow click I am triggering  this function by passing html element as the newValue & index value to be move as the columnValue.

parameters (newValue = "<option> Test List Element</Option>", columnValue = 25)


It works correctly in Chrome & IE, but fails in Firfox. :(

Because in FF .insertBefore & .insertAfter expects both arguments to be DOM element references. 

In the above example argument pass as string & integer, they are not treat as Document Object Mode.

So to overcome the above issue I have replaced the passing parameters as follows.



So to overcome the above issue I have replaced the passing parameters as follows.

I think this will be helpful for you to user .inserBefore or .insertAfter in js.

B' happiiiiiii :) always.

Refer : http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/136894/.insertbefore-not-working-in-ff

Wednesday, November 27, 2013

Using of XML for dynamic parameter passing

In this blog my main concern is to describe, how to use XML reader as dynamic parameter passer.

Basically XML files use the classes and methods inside the System.XML namespace of the .NET Framework.

System.Xml namespace is the reference main class. To read xml files, we can use the XmlReader class.

Basically, reading xml files using XmlReader requires you to look carefully at the structure of your XML.

Ex XML code:

Ex C# code:

So the above Object Array we can use as parameters.

I konw you may wonder how we can use as dynamic parameter. If  the program is depending on custom based we can customize the xml without changing the backend code.

I think it will be really easy to maintain mutiple customer based applications.

Enjoy...

b' Happiii always,,,

Thursday, October 3, 2013

DataBinding with knockout loop with in the loop

 In a special scenario I try to apply a loop with in a loop via knockout data binding.

As in the below example I try  to apply knockout foreach: as well as the general for loop

When I am try to bind data using knockout when the page load it work fine. But when post back it throws an error
                       "You cannot apply bindings multiple times to the same element."
and also data repeating wrong way.  

Script and the view as in below. From the controller it returns the required view model.

Script:


View:

 
Main scenario in there is from knockout  multiple binding is not allow. So in the $(document).ready ko.applybinding has to be done.

Thankful to stackoverflow & my Tech Lead to help me to fix the issue..

Refer: stackoverflow.com/questions/19136393/databinding-issue-with-knockout

Be Happy........ :)

Friday, August 23, 2013

Simply Query WHERE in Special scenario

Today I got to know the most effective way to query the result from WHERE condition in a special scenario.

For example:
If you want to get the result set from Employee table
 When Select All Department or When Select One Department (only two options are there)

 You have to consider only WHERE column = <some value>
 If select All no need to worry about WHERE column IN (<all values>) or else IF ELSE or SWITCH Conditions

 Just simple you can get the result via OR logic
 Remember only one statement or both statement has to be TRUE to return in OR gate.


WHERE DepartmentId in (@Dep)  OR @Dep in (0)
when select all no value passes. So if pass 0 the logic change as
WHERE DepartmentId in (0)  OR @Dep in (0) -> TRUE OR TRUE

Look how it simple. :)

Wednesday, August 21, 2013

Email sending via MvcMailer

In ASP.Net MVC 3/4, MvcMailer provides you with an ActionMailer style email sending

To Install in Nuget Package : PM> install-package MvcMailer

Follow the simple example: Leave Request Mail

1) Define a mail model for the Leave Request :

    public class LeaveRequestMailModel
    {

       //main attributes
        public string Subject { get; set; }
        public string ToMail { get; set; }
        public string FromMail { get; set; }
        public string Message { get; set; }
        public string ViewName { get; set; }

       //customized attributes
        public string CustomEmployeeId { get; set; }
        public string EmployeeName { get; set; }
        public string FromDate { get; set; }
        public string ToDate { get; set; }
        public string LeaveType { get; set; }       
        public int LeaveApprovalHistoryId { get; set; }
        public int LeaveTransactionId { get; set; }
    }

2) Define Sending mail Service :


As you see here, populate method will call you back with an already instantiated MvcMailMessage object so you can set its properties as required.
MvcMailMessage is an extension of MailMessage from the core .Net library, with new properties added so you can specify the ViewName, MasterName, LinkedResources etc.

3) Design View for the Leave Request Email Template:

Here you can see a section of the View. In there I have  used inline css. Else email display without any styles.

4) Call Sending mail service via the controller :


Define the parameters relevant to the Leave request mail as in the above.

5) Setup the web config :


6) Finally you can run and see the output as follow:




It is really cool.  Those who are interested on this also better try and see.

Refer : https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide
            http://smsohan.com/blog/2012/10/02/mvcmailer-new-api/