Friday, September 28, 2007

Populating a Password Textbox at Runtime

Having an with a password property (TextMode="Password"), you cannot simply set the textbox's .Text attribute at runtime to populate the control with a value. Rather, you have to do the following:


this.txtPassword.Attributes["value"] = {whatever value from variable or DB}

Many thanks to:
http://aspadvice.com/blogs/joteke/archive/2005/02/03/_4000_ASP.NET-Forums_3A00_-How-to-set-text-to-a-Password-TextBox_3F00_.aspx

Wednesday, September 12, 2007

Converting Enum instance to string for evaluation

I came across a situation where I needed to get a Querystring value and evaluate it against a Enum used for display modes.

// Display Mode Enum
public enum Mode
{
View,
Add,
Edit
}

// Evalutate Querystring
object oDisplayMode = Request.QueryString["mode"];
if (oDisplayMode != null)
{
displayMode = (Mode)Enum.Parse(typeof(Mode), oDisplayMode.ToString(), true);

// Put into ViewState for next postback
ViewState["DisplayMode"] = displayMode;
}

Monday, September 10, 2007

Get names of all columns for a table in SQL Server

SELECT name
FROM syscolumns
WHERE [id] = OBJECT_ID('table_name')