Archive for July, 2008

Until recently, I had always used javascript to allow the enter key to submit a form (as seen in a previous posting called Submit Form On Enter Key Solution). Since then, I was queued into a GUImethod of controlling enter key form submissions in Visual Studio 2008 (and I’m sure this works in other versions as well).

How to submit a form in Visual Studio 2008To do this in the GUI style, click on the form of the page and then select the elements properties. Under the ASP.NET subheading, there is a form property called DefaultButton. Insert the button control id of the default button. This will essentially submit the form on enter (by performing the action on the specified button). The image to the left is an example of the form property section with a default button set to btnSetCookie. Note that for one reason or another, intellisense is not enabled on this property and you will have to manually type in the button control id.

Of course, you are not constrained to doing this in the GUI style. To submit a form on enter programmatically, simply find the form and insert the keyword defaultbutton=”BUTTON_CONTROL_ID_HERE”. Below is an example of how the above example would look programmatically.

<form id="frmTestForm" runat="server" defaultbutton="btnSetCookie">

One of my favorite and most heavily used PHP common functions retrieves variables from the query string. I found that without this function, I was inefficiently checking if the variable existed, and if not, I was then was manually setting a default value. The function takes in two string variables that handle the above problem. $urlStringName is the name of the variable as stated in the query string and $returnIfNotSet is the string that will be returned if the $urlStringName is not found. Check out the code snippet below:

function getUrlStringValue($urlStringName, $returnIfNotSet) {
  if(isset($_GET[$urlStringName]) && $_GET[$urlStringName] != "")
    return $_GET[$urlStringName];
  else
    return $returnIfNotSet;
}

Let’s run through an example of how this function works. Assume we have the following url:

http://www.victorchen.info/index.php?firstName=Victor&lastName=Chen

If I am looking to find the string value of the first and last name, but return john or doe if the query variable firstName or lastName is not found, respectively. I would write the following:

$firstName = getUrlStringValue("firstName", "john");
$lastName = getUrlStringValue("lastName", "doe");

In this example, we would expect to store $firstName to be “Victor” and $lastName to be “Chen”.

However, if the url arrives as (missing the lastName query string variable):

http://www.victorchen.info/index.php?firstName=Victor

We can expect to see $firstName as “Victor” and $lastName as “Doe”.

While migrating an old application from Visual Studio 2003 to Visual Studio 2008, I came across what seemed to be a dll mismatch error. I had to remove the original dll from the references because of conflicts with the new 3.5 framework to a new version of the dll as found in the 3rd party clients default installation location (somewhere in C:\Program Files). After this change, visits to a page that utilizes the 3rd party dll would crash with this error (where dll1 was the temporary location of the original dll and dll2 was the temporary location of the new dll):

CS0433: The type exists in both [dll1] and [dll2]

The old dll temporary location was at C:\Windows\Microsoft.NET\Framework\v1.0.3705\Temporary ASP.NET Files and the new dll temporary location was at C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files. Note that these locations will vary depending on the Microsoft.NET framework version you are using.

My first thought was that the temporary location somehow got out of sync, so I decided to rebuild the solution, but this was unsuccessful. My next idea was the delete both temporary folders, but had problems because the folders were locked. The last thing I tried was to manually add a copy of the dll to the Solution’s bin folder and reference that specific copy. This fixed the problem!