Field Validations – ASP.NET

Date Text Field Validations

Requirement:Validate entering birth day in a text field with mm/dd/yyyy format.

code in the .aspx or in .ascx


<asp:TextBoxID=”dateOfBirthTextBox”runat=”server”></asp:TextBox>

<asp:RequiredFieldValidatorID=”dateOfBirthRequiredFieldValidator”runat=”server”

ControlToValidate=”dateOfBirthTextBox” ErrorMessage=”Required”></asp:RequiredFieldValidator>

<asp:RangeValidatorID=”dateOfBirthRangeValidator”runat=”server” ControlToValidate=”dateOfBirthTextBox”

ErrorMessage=”Please enter a past date in mm/dd/yyyy format”Ā  Type=”Date”Display=”Dynamic”></asp:RangeValidator>

code in the .cs file – Under OnInit or PageLoad methods

this.dateOfBirthRangeValidator.MinimumValue = DateTime.MinValue.ToString(“MM/dd/yyyy”);
this.dateOfBirthRangeValidator.MaximumValue = DateTime.Today.ToString(“MM/dd/yyyy”);

Visual Studio – Tips and Tricks

Moving between active(opened) files in Visual Studio;

Default : Use ctrl+tab to move forward between active (opened) files and ctrl+shift+tab to move back between active files.

Change it : Tools->Options->Keyboard
Select Window.NextDocumentWindowNav command from the drop down list Window.NextDocumentWindowNav
Assign another key combination

Moving Between Documents in Visual Studio

Binding a Dictionary to a Drop Down List

Binding data from a Dictionary is not so challenging as “Key” and “Value” pairs can be used for the drop down list properties. Following code samples show the results after assigning data source to the drop down list.

Before

Dictionary genderDictionary = new Dictionary();
genderDictionary.Add(1, "Male");
genderDictionary.Add(2, "Female");
genderDictionary.Add(3, "Transgender");

this.ddlGender.DataSource = genderDictionary;
this.ddlGender.DataBind();

Before Assign Key Value Pair

Continue reading “Binding a Dictionary to a Drop Down List”

CRM Installation Error : Sql instance name must be the same as computer name

When the Sql server instance is differ from the machine name, this error will be given as a result of verification tasks under the system check of CRM installation. Most of the time this happens if the Sql server instance changes after the first installation and reinstallations.

CRM Installation Sql Error
CRM Installation Error

Anyhow this can be fixed easily as we can use few sql stored procedures. Follow the steps listed below.

Continue reading “CRM Installation Error : Sql instance name must be the same as computer name”