Thursday, February 7, 2008

Formating Dates in the GridView

I set up a bound GridView. I had several bound fields. A couple of the field were dates. The data source was a date time field. I did not want the time portion, so I used
DataFormatString="{0:MM/dd/yyyy}" on the BoundFields. On my development box it stripped off the time. When I deployed to the server it was still showing the times.

The solution was to add HtmlEncode="False" to the bound fields.

Thursday, January 31, 2008

Using CustomValidator to Validate empty (blank) Textbox

I started my page by using a RequiredFieldValidator, but later found that I needed to validate on more complex criteria as well as if the field is empty. When I added the CustomValidator I found that my code was not firing if the TextBox was empty. After researching this I found that there is a property of the CustomValidator called ValidateEmptyText. The default is false. Once I set this to true it worked and I was able to remove the RequiredFieldValidator.

I'm not sure which version of .Net this property exists in. My page was running on .Net 2.0.

Friday, January 11, 2008

Checking the Value of an HTML Checkbox in Classic ASP with VBScript

I spent several hours being rolled around by this. It appears as though that when you do request.Form("Control") the parameter takes the value of the name property and not the value of the ID property. So I got myself confused since I was doing some stuff client side in javascript as well as in VBScript server side. I generally use getElementById in javascript.

I was only setting the ID property and trying to use the request object to find the id.

Monday, November 19, 2007

Modal Browser Window Spawns in New Window When Submitting to Self

I had the problem with an aspx page that when I changed it to a modal window it would pop a second copy of itself into another non modal window when the submit button was clicked.

The solution ended up being to add <base target="_self"> between the <head> and </head> tags. Don't know why I had to do that, but so far it seems to have resolved the problem.

Wednesday, October 31, 2007

Switch Case C#

For some reason I find myself having to look this up every time I go to use it.

Switch is like Select in VB. The structure of it is as follows.

switch (variable)
{
case value1:
statements;
break;
case value2:
statements;
break;
case value3:
statements;
break;
default:
statements;
break;
}
  • Switch is followed by a variable in parenthesis. This the variable that you are checking the value of.
  • Each value that you want to check the variable against is in a case vale block.
    • Must have a colon after the value.
    • Each statement int he block must be terminated with a semicolon.
    • Each block must have a break at the end of it. C# does not allow falling through to one case to the other, but you can do several empty cases in a row that all fall through to one code block. The break tells it not to do this. For example:
      case 1:
      case 2:
      case 3:
      DoSomething();
      break;
      In this example if the variable is 1, 2, or 3 it runs do something.
  • There can be a default case that executes if the variable does not match any of the cases.
  • It appears as though one can include a goto statement in their case block also. For example "goto case 17" jumps you to case one. You could execute code in case 45 and then jump to case 17 and run its code as well, even though the variable is not equal to 17.
  • All of the case blocks are surrounded by {}. The opening { is after switch (variable). The closing } is after the last case block of code.

Tuesday, September 25, 2007

Debugging Classic ASP

This has been a pain to me in Visual Studio 2005. I finally Googled it and found that VS2005 has been crippled in many ways when it comes to debugging classic ASP pages. One recommendation I saw was to use VS2003, which had more or easier debugging for classic ASP. I can't say if this is true or not since I have never used VS2003 to debug classic ASP pages.

One thing I found that some say can make it easier in VS2005 is listed below:
  • IIS Manager -> Rt Click Web Sites -> Properties -> Home Directory -> Configuration -> Debugging -> Enable ASP Server-Side script
Another thing I found was that some talked of attaching to the IIS ASP process (w3wp.exe). I was not able to get this to work, but I only tried for a couple of minutes.

Wednesday, July 11, 2007

Cannot implicitly convert type 'string' to 'method group'

I run into this now and again in C#: Cannot implicitly convert type 'string' to 'method group'

This usually means that you have not included the parenthesis at the end of a method call. For example, ToString(). Many times I will do:

if (str == var.ToString)

or

str = var.ToString;

It throws the about error because I needed to do:
if (str == var.ToString())

or

str = var.ToString();