How do I generate a random number within a range?

Using .NET you can easily generate a random number withing a range, by using the Random class. In the following example a random number between 1 and 69 will be generated: System.Random RandNum = new System.Random();int MyRandomNumber = RandNum.Next(69); To generate a random number between 1986 and 2005 you would use: System.Random RandNum = new System.Random();int MyRandomNumber = RandNum.Next(1986, […]

How can I set the ASP.NET validators to be visible by default?

To make the validators on a page visible by default you can call the page’s Validate() method when it is loading, as in: private void Page_Load(object sender, System.EventArgs e){    if (!IsPostBack) { Page.Validate(); }} Or if you want to make visible only one validator, use: private void Page_Load(object sender, System.EventArgs e){ if (!IsPostBack) {    // Where reqEmail is […]

How do I retrieve the Major and Minor application (assembly) version and the Build and Revision number?

You can nicely retrieve the major and minor version of your application by using the Version class to retrieve and decode the version from the assembly. Version vrs = new Version(Application.ProductVersion);MessageBox.Show(“Major: ” + vrs.Major + “\r\nMinor: ” + vrs.Minor); Also, you can get the build and revision number using the rest of the properties: Version vrs = new Version(Application.ProductVersion);MessageBox.Show(“Build: […]