This is a dumping ground of software development topics that I've run across and found interesting (mainly .NET development). Many topics are covered more thoroughly in other places, and much of the information is gleaned from other places, and I'll try to credit those sources when possible.

Wednesday, August 05, 2009

ASP.NET Panel with empty GroupingText

Using the GroupingText property of an asp:Panel will cause a pretty box to surround a group of controls, but sometimes I want to have that box without the text. I set GroupingText=" " hoping it would be interpreted as no text, but instead you can see the space in the box, which is annoying. Checking out the client side HTML (and MSDN documentation), I found the panel is represented as FIELDSET and LEGEND elements. By replacing the asp:Panel elements with fieldset, and not specifying a legend, I get the caption-free box I want. Note that you may have to put your fieldset in a div to get the style you want, like width. Simple example below:

<asp:Panel runat="server" GroupingText="Group of controls" Width="300px">
A panel using GroupingText="Group of controls"
</asp:Panel>
<br />

<asp:Panel runat="server" GroupingText=" " Width="300px">
A panel using GroupingText=" " (see gap in box above?)
</asp:Panel>
<br />

<div style="width: 300px;">
<fieldset runat="server">
A fieldset to get a solid box with no text.
</fieldset>
</div>

Wednesday, February 13, 2008

C# .NET: Ignoring Alt-F4 key combination

Alt-F4 is a shortcut that closes a window. For some reason you may not be fond of this behavior. After doing some digging around, I finally found a good method of ignoring this request - overriding the ProcessDialogKey method. You can go do more research if you'd like, but the basic code is as follows:

protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == (Keys.Alt | Keys.F4))
return true;
else
return base.ProcessDialogKey(keyData);
}

Friday, February 08, 2008

Getting a Batch File's Command Line

I can't remember where I got this batch script, but it's handy for getting the complete command used to call the batch file. For instance, the text written to the file may be something like this: "C:\cmdlinetest.bat" -install -param2 some other stuff...
-------------------------------------------------------------------------

REM Set variable 'line' to first token in the command line.
set line=%0

REM Loop through the next token, concatenating value, then shifting the
REM command line to process the next token. Stop when token is empty.
:loop
set line=%line% %1
if "%1" == "" goto :done
shift
goto loop

REM Done finding command line arguments, echo to file.
:done
echo %line% > C:\cmdline.txt

Thursday, May 03, 2007

OuterXml for Java

Java can be extremely frustrating, particularily because there always seems to be many many different ways to do a simple task. For example, I needed to get a fragment from an XML document which seems easy enough. .NET has the XmlNode class which has a property OuterXml. Done. However, no such simple equivalent exists for Java, at least in my limited experience. I don't claim to be an XML expert, so I'm not about to write a diatribe. After a couple of hours, I found this guy's blog, which I used as a basis for the method below. You can figure out how to get a org.w3c.dom.Node object, that's another painful tale...


public static String getOuterXml(Node node)
throws TransformerConfigurationException, TransformerException
{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty("omit-xml-declaration", "yes");

StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(node), new StreamResult(writer));
return writer.toString();
}

Thursday, April 05, 2007

Windows Firewall for FTP

This is silly, but it hung me up for more than a few minutes. I was trying to FTP from a laptop to my desktop PC (running Microsoft's IIS FTP server). The client would claim it was connected, then after a few seconds, report "Connection closed by remote host." So I'm guessing it's a firewall problem, and I'm right (for a change), but it was still not easy to find. So below are the screen shots of the magical checkbox I needed to check.

Thursday, February 01, 2007

Random Password Generator

I needed to create a random password. First I found this short method, which didn't work. Then I found this guy agreed with me. His code works, but not so hot in my test program. The parameterless Random constructor uses a time-based seed value (per millisecond?) so there are duplicates. The code I ended up with reuses a single Random member.

Then there's the holy grail, which was too much for the requirements I was working with, eight alphanumeric digits only. Simplicity is divine.


private Random m_random = new Random();

public string CreateRandomPassword(int length)
{
char[] chars = new char[length];

int index = 0;
while (index < length)
{
char c = (char)m_random.Next(48, 122);
if (Char.IsLetterOrDigit(c))
{
chars[index] = c;
index++;
}
}

return new string(chars);
}

Thursday, December 14, 2006

C# vs. Java

Here is an interesting comparison of C# and Java. I like the way the sections are organized by:
- Same functionality.
- Similar functionality.
- Same concept, but totally different implementation.
- Unique C# functionality
- Unique Java functionality

http://www.25hoursaday.com/CsharpVsJava.html

Followers