Wednesday, March 12, 2014

Use anchor to pop up window

Using an anchor to pop-up a window with JavaScript
Anchor tag:
<a href="javascript:popWindow('');">Pop Window</a>

<script type="text/javascript">
   function popWindow(hrefTarget) { 
   // Pop up the window, "_blank", "width=463,height=500,resizable=yes");

Alternatively, returning a false will prevent the anchor from linking:
<a href='' onclick='FunctionCall(); return false;'>Pop Window</a>

Thursday, March 6, 2014

Using RadioButton within Repeater

To turn off radio buttons within a Repeater when a selection is made, the javascript below will assist.

<script language="javascript" type="text/javascript">  
function RB_CheckChanged(current) {
  for (i = 0; i < document.forms[0].elements.length; i++) {
      elm = document.forms[0].elements[i];
      if (elm.type == 'radio') {
         elm.checked = false;
   current.checked = true;

<asp:Repeater runat="server" ID="RBRptr">                                               
     :RadioButton runat="server" ID="Rb" onclick="RB_CheckChanged(this);" Text='<%  #DataBinder.Eval(Container.DataItem, "name")%>' />


Tuesday, February 25, 2014

Find DLL location in Global Assembly Cache (GAC)

This method will give the location of an assembly from GAC

private string FindDLLInGAC(string dll)
{    foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
    {        if (a.ManifestModule.ScopeName.Equals(dll))
             return a.Location;
    }     return null; //Not found

string asmLocation = FindDLLInGAC("TheDLL.dll");
Assembly asm = Assembly.LoadFile(asmLocation);
var thetype = asm.GetType(theType, true, false);

Monday, February 24, 2014

Load Assembly to dynamically create an instance of a class

This will load an assembly and dynamically create an instance of a class.

string asmLocation = Path.Combine(AssemblyDirectory(), "TheDLL.dll");
Assembly asm = Assembly.LoadFile(asmLocation);
var theType = asm.GetType("TheType", true, false);
IRunnable runnable = Activator.CreateInstance(theType) as IRunnable;


private string AssemblyDirectory()
{    string codeBase = Assembly.GetExecutingAssembly().CodeBase;
    UriBuilder uri = new UriBuilder(codeBase);
    string path = Uri.UnescapeDataString(uri.Path);
    return Path.GetDirectoryName(path);

Tuesday, January 28, 2014

SQL Reference two database instances in a query

Within a SQL query or stored procedure, multiple database tables can be referenced.  The full database name just needs to be specified in the query.



FROM Appointment a

INNER JOIN TableLog.dbo.Appointment al ON al.appointmentid=a.appointmentid

WHERE a.appointmentid = @appointmentid

C# use a Type in a generic method definition

To use a Type within a generic method initialization, it can be accomplished with:

MethodInfo method = typeof(NameOfClass).GetMethod("MethodName", BindingFlags.Public | BindingFlags.Static);

method = method.MakeGenericMethod(type);
string results = (string)method.Invoke(null, new object[] { props[key] });

Tuesday, November 19, 2013

SQL query runs fast but stored procedure equivalent runs slow

If a SQL stored procedure is running slow, but the query is quick, try declaring local variables to replace the parameters in the stored procedure.

* Not sure why this works, please leave a comment if you have any info.

Replace the stored procedure paramters with local variables

ALTER PROCEDURE [dbo].[SlowProcedure]
--Add @PARAM_ variables to speed up query

                  @enddate SMALLDATETIME

SELECT  @begindate = @PARAM_begindate,
                @enddate = @PARAM_enddate

FROM [Table]
WHERE Date BETWEEN @begindate AND @enddate