3 Things I Learned This Week (2014-12-19)

One of the hosts of the Ruby Rogues podcast recently recommended taking time each week to write down three things you learned. I’m going to try this for awhile and see if its helpful.

Nuget .nuspec files add Referenced DLLs to the bin/ During Build

If your project depends on a local dll, one that is not already available via nuget, you can add it to the <references> section of the .nuspec. When your library is referenced in Visual Studio, that DLL will come along for the ride even though theres no direct reference in Visual Studio.

Compiling Ruby on Cygwin

Make sure you have all the build tools and libraries then use the instructions from the ruby-build project.

  • gcc
  • gcc-core
  • git
  • libtool
  • libncurses-devel
  • libncurses
  • make
  • openssh
  • openssl
  • openssl-devel
  • zlib
  • zlib-devel
  • libyaml
  • libyaml-devel
  • patch
  • patch-utils
  • make
  • libcrypt
  • libcrypt-devel
  • libiconv
  • libiconv-devel
  • curl
  • wget

Some of those may not actually be required but you should have them anyway :)

HT: Jean-Paul S. Boodhoo

Developing ASP.NET UserControls That Target and Modify Another Control

Sort of like how the ASP.NET Validation controls have a ControlToValidate property that takes the string ID of the desired control.

I was developing a wrapper for a jquery modal plugin and wanted the modal to declare which control triggered it to open:

1
2
3
4
5
6
7
8
9
<a runat="server" ID="ModalTrigger" href="#">Open Modal</a>

<!-- Near the Bottom -->
<uc:MyModalControl runat="server" ID="Modal"
ModalID="modal-one" TriggerControl="ModalTrigger">
<Contents>
This is the modal stuff
</Contents>
</uc:MyModal>

My modal control would need to add a data-reveal-id="modal-one" attribute to the Open Modal link.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
protected void Page_Load(object sender, EventArgs e)
{
Page.PreRender += Page_PreRender;
}

void Page_PreRender(object sender, EventArgs e)
{
if (TriggerControl == null)
return;

AddDataRevealIdToTriggerControl();
}

private void AddDataRevealIdToTriggerControl()
{
var triggerControl = FindControlRecursive(Page, TriggerControl) as HtmlControl;
if (triggerControl != null)
triggerControl.Attributes["data-reveal-id"] = ModalId;
else
throw new InvalidOperationException(
string.Format("Could not locate TriggerControl '{0}'. Did you include runat=\"server\"?", TriggerControl));
}
}

public string TriggerControl { get; set; }

private static Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
return root;

foreach (Control c in root.Controls)
{
var ctr = FindControlRecursive(c, id);
if (ctr != null)
return ctr;
}

return null;
}