Monday, August 11, 2008

Get DayNames in a given Culture

Sometimes we may need to have the day names in a week for a given culture. With ASP.NET CultureInfo class you can loop through the DateTimeFormat.DayNames and get them. Here is the example of it

using System.Globalization;
CultureInfo ci = new CultureInfo("ar-ae");
// gets the day names of arabic, arab emirates
foreach (string day in ci.DateTimeFormat.DayNames)
Response.Write(day + " ");

Depending on the culture you want, you can get the CultureInfo reference for that corresponding culture. The DateTimeFormat also provides other values like month names, first day of week etc.,

Good Luck

Preventing Duplicate Record Insertion on Page Refresh

I have found a good article on preventing the duplicate record insertion on page refresh by Terri Mortan.
Check the article here http://aspalliance.com/687

Friday, July 25, 2008

Create New Account Manually

Try this

protected void Create_Click(object sender, EventArgs e)
{
MembershipCreateStatus createStatus;
MembershipUser newUser = Membership.CreateUser(Username.Text, Password.Text, Email.Text, passwordQuestion, SecurityAnswer.Text, true, out createStatus);

switch (createStatus)
{
case MembershipCreateStatus.Success:
CreateAccountResults.Text = "The user account was successfully created!";
break;

case MembershipCreateStatus.DuplicateUserName:
CreateAccountResults.Text = "There already exists a user with this username.";
break;

case MembershipCreateStatus.DuplicateEmail:
CreateAccountResults.Text = "There already exists a user with this email address.";
break;

case MembershipCreateStatus.InvalidEmail:
CreateAccountResults.Text = "There email address you provided in invalid.";
break;

case MembershipCreateStatus.InvalidAnswer:
CreateAccountResults.Text = "There security answer was invalid.";
break;

case MembershipCreateStatus.InvalidPassword:
CreateAccountResults.Text = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character.";
break;

default:
CreateAccountResults.Text = "There was an unknown error; the user account was NOT created.";
break;

}
}

for more info visit
http://www.asp.net/Learn/Security/tutorial-05-cs.aspx
Good Luck