Tuesday, March 29, 2011

Pass Values among frames/iframe using jQuery - untested - only a snippet

The following is untested code used to assist in a question located here: Link

Parent Document (Main.html)

<!-- parent window (main.html) -->
<input id="inpA" name="inpA" type="text" />
 
<!-- wire this button trigger up to open the dialog -->
<button id="triggerThatOpensDialog">Open Dialog</button>

Child Document (Child.html)

<!-- in the child/popup dialog (child.html) -->
<input id="inpB" name="inpB" type="text" />
<button id="triggerToPopulateParent">Callback to Parent</button>
 
<script type="text/javascript">
    $(function () {
        $("#triggerToPopulateParent").click(function (e) {
            e.preventDefault();
            // text input on the child/popup
            var $inputOnChild = $("#inpB");
 
            // text input on the parent that opened the child/popup
            var $inputOnParent = $("#inpA", window.opener.document);
 
            // set the parent textbox value using the child textbox value
            $inputOnParent.val($inputOnChild.val());
        });
    });
</script>

Dependency Injection (DI) Registration (using StructureMap) used is non-IDependencyResolver scenarios

Bootstrapping code for dependency injection (DI) registration (using StructureMap) used is non-IDependencyResolver scenarios - put this into a separate file:

public static class BootStrapper
{
    public static void Bootstrap()
    {
        ObjectFactory.Initialize(x =>
        {
            x.AddRegistry(new EFRepositoryRegistry());
            x.AddRegistry(new ServicesRegistry());
        });
 
        DependencyResolver.SetResolver(
            t =>
            {
                try
                {
                    return ObjectFactory.GetInstance(t);
                }
                catch
                {
                    return null;
                }
            },
            t => ObjectFactory.GetAllInstances<object>().Where(s => s.GetType() == t)
            );
    }
}

Invoke the DI registration in the Application_Start() method in the Global.asax:

protected void Application_Start()
{
    BootStrapper.Bootstrap();
}