Test if Item Selected in ListBox

Testing to ensure that a ListBox has a selected item on submit.

Here all is done using the built in asp.net functions.

Alternatively, could use JavaScript or JQuery. Note that to do so would need to assign variables to the listbox element for the testing.

1. Field Validator

Here’s the list box with its items. I find fruit and veg a ready source of names when trying out examples such as this.

<asp:ListBox ID="lbxFruit" runat="server">
    <asp:Button ID="btnSubmit" runat="server" Text="Button" />
    <asp:RequiredFieldValidator ID="rqdFruit" runat="server" 
        ControlToValidate="lbxFruit" Display="Dynamic" 
        ErrorMessage="Required! Please choose 1!">Required! Please choose 1</asp:RequiredFieldValidator>

With the RequiredFieldValidator using the Dynamic display option gives instant feedback if the field isn’t completed.

2. On Form Submit

If lbxFruit.SelectedIndex = -1 Then
Response.Write("Please select at least one item")
End If

In this example the form is submitted. The work is then done on the server to check whether the submission is correct.

Here the test is whether the SecletedIndex has a value of -1, ie not set.

For simplicity I have simply shown a response write. The presentation should be better with a label populated with the details of the field which has been selected, I assume that other fields will also be similarly tested.

Also I’ve not shown an abort. If there’s an error on the form then further actions on the field won’t be processed. The page will be returned back to the visitor as many times as needed until its correctly filled out.

3. JavaScript/JQuery

Custom javaScript or JQuery can be written.

To be able to make such actions the ID of fields the fields will be required. This will be done by assigning to a variable the reference on the page, as composed by asp.net.

var lbxFruit = document.getElementById(“<%= lbxFruit.ClientID %>”).innerText;


I prefer in practice to use a combination of the two examples above.

By first checking whether the use has filled out the form correctly the responses are immediate. The user experience is the better for it

and we impose less impact on the server.

Once the user input has been validated then it can be submitted to the server and checked. Checking is required because there’s the chance that the user input has escaped the validation and who knows maybe the page has been edited to enable the trial of input of bad data.

WordPress Using phpMyAdmin to add a New User

Wishing to add a new administrator user to a WordPress website. How could I do this if I don’t have access to an existing user account?

Fortunately I had access to the hosting control panel giving me the option to use phpMyAdmin.

The equivalent actions can be created by the use of a custom php file, which is saved on the website and run once. There can be something comforting about interacting with forms rather than composing a piece of script. Potentially less chance of making an error with the forms. A script can be harder to view for malicious intent, or simply an error in copying and customising to the particular circumstance, can be catastrophic. Having said that it can be easy to click on the wrong button, a delete rather than insert, as the page is rendering.

A new user can be added to a WordPress website using phpMyAdmin, available through the hosting control panel.

Take care there are steps involved in this article which seriously affect your website.

Using phpMyAdmin we’ll add a new administrator user.

Login to your control panel and open phpMyAdmin. This is likely to be found on a page with a number of other icons. Finding this page will depend upon the layout of your hosting provider.

Once opened shown on the left are the databases associated with the account. If it’s not clear which one is used by the website this will need to be discovered.

To check which database is in use by the website return to the website control panel and click on the icon for the file manager. This will show a directory and file view. You may need to navigate into a folder called public_html. Look for and open a file called wp-config.php.

Using phpMyAdmin add user wp-config

Here we are looking for the entry define(‘DB_NAME’, ‘wordpress’); In this example the database is wordpress. Note this value, it is the database which we wish to select within phpMyAdmin.

Back to the control panel view of icons. Select phpMyAdmin once more. In the left view of the phpMyAdmin page there’s the list of databases. Select the one found previously.

Using phpMyAdmin add user table overview

WordPress uses a default table prefix of wp_ however It’s possible that the prefix of your tables may be otherwise. For ease I’m using the default in my references.

The tables which we are interested in are wp_users and wp_usermeta.

I have found that clicking on a table in the left menu list of tables allows me to see the entries and to edit these but I can’t add (insert) a new row. To do this it’s back to the list of tables in the main window with the edit options along side to the right in the row. Here I select insert.

Insert new user in table wp_users

Click on insert to open a clean entry form to add our new user details.

Using phpMyAdmin add user wp_users insert entry

In this view the fields are completed as follows:

  • ID: leave this entry
  • user_login: the login username, take care to avoid obvious entries, such as the person’s name. But, including a part of the users name will help in identification. Mix it with some additional random characters.
  • user_pass: a password for the user. Select md5 from the dropdownlist to the left and enter the password. Take care to ensure suitable complexity.
  • user_nicename: the name by which the user will be known.
  • user_email: the email address for the user
  • user_url: the website for the user, its possible that its the same as the website.
  • user_registered: select the date when the user was registered. Unless you are obsessive regards the date/time select yesterday’s date – its probably close enough.
  • user_activation_key: leave this entry
  • user_status: leave this entry
  • display_name: the name shown

Add user role abilities in table wp_usermeta

If we leave our newly created user as is we’ll be able to login but not a lot else.

Our aim is to create a new user with administrator privileges. To do this we set the capabilities of the user

If you didn’t note the id for the newly created user revisit the wp_users table to make a note of it.

Back to the home screen view of the database with the tables listed click on insert on the row for wp_usermeta.

Using phpMyAdmin add user wp_usermeta wp_capabilities

Fill in the I’d for the user, plus the fields

  • umeta_id: leave this entry
  • user_id: enter the user id value
  • meta_key: wp_capabilities
  • meta_value: a:1:{s:13:”administrator”;s:1:”1″;}

If you have changed your database prefix from wp_ don’t forget that wp_capabilies will also need to change accordingly.

There’s another entry in the wp_usermeta table to add

Using phpMyAdmin add user wp_usermeta wp_user_level

The values for this one are:

  • umeta_id: leave this entry
  • user_id: enter the user id value
  • meta_key: wp_user_level
  • meta_value: 10

A review of the list of entries, looking at the last page:

Using phpMyAdmin add user wp_usermeta list

That leaves trying to login with your newly added user and seeing whether you have administrator rights over the website.

A few simple steps, along with access to phpMyAdmin via the website hosting control panel, can be used to add an administrator user to an existing WordPress website.

Replacing Firefox-esr with Firefox

I’d like to install the regularly updated version of Firefox.

A new installation of Debian was showing as using the stable long term supported Firefox ESR (extended support release) package.

The task was to remove the package firefox-esr and install the package firefox, or its installation equivalent.

To delete the currently installed package firefox-esr will be

apt remove firefox-esr

However, that can wait until the other package is all installed and shown to be working.

Yes, you can run both versions of Firefox.

To delete the stable version of Firefox and install in its place the I would prefer to use the more regularly updated version of Firefox.

For reference the initial content of the file /etc/apt/sources.list was:

deb http://mirror.ox.ac.uk/debian/ buster main
deb-src http://mirror.ox.ac.uk/debian/ buster main

To search for the installation package for Firefox, it will list all packages with a reference to firefox, use:

apt-cache search firefox

Comparing the new computer installation against an existing operational computer.

For the new computer configuration no Firefox packages were shown, but there were the equivalent language versions of firefox-esr, but on the already operational computer

The one which was already configured, there was a limited number of firefox-esr packages shown, with lots of language variations on the firefox package.

firefox - Mozilla Firefox web browser
firefox-l10n-ach - Acoli language package for Firefox
firefox-l10n-af - Afrikaans language package for Firefox
firefox-l10n-all - All language packages for Firefox (meta)
firefox-l10n-an - Aragonese language package for Firefox
firefox-l10n-ar - Arabic language package for Firefox
firefox-l10n-as - Assamese language package for Firefox
firefox-l10n-ast - Asturian language package for Firefox
firefox-l10n-az - Azerbaijani language package for Firefox
firefox-l10n-be - Belarusian language package for Firefox
: : :
firefox-l10n-sv-se - Swedish (Sweden) language package for Firefox
firefox-l10n-ta - Tamil language package for Firefox
firefox-l10n-te - Telugu language package for Firefox
firefox-l10n-th - Thai language package for Firefox
firefox-l10n-tr - Turkish language package for Firefox
firefox-l10n-uk - Ukrainian language package for Firefox
firefox-l10n-ur - Urdu language package for Firefox
firefox-l10n-uz - Uzbek language package for Firefox
firefox-l10n-vi - Vietnamese language package for Firefox
firefox-l10n-xh - Xhosa language package for Firefox
firefox-l10n-zh-cn - Chinese (China) language package for Firefox
firefox-l10n-zh-tw - Chinese (Taiwan) language package for Firefox
: : :
firefox-esr-l10n-be - Belarusian language package for Firefox ESR
firefox-esr-l10n-ia - Interlingua language package for Firefox ESR
firefox-esr-l10n-my - Burmese language package for Firefox ESR
firefox-esr-l10n-ne-np - Nepali (Nepal) language package for Firefox ESR
firefox-esr-l10n-oc - Occitan language package for Firefox ESR
firefox-esr-l10n-ur - Urdu language package for Firefox ESR

Can I simply install the firefox package then?

E: Package 'firefox' has no installation candidate

Should I use one of the language representations, as listed in  the search?

apt install firefox-l10n-uk

Once again it couldn’t find the package:

E: Package 'firefox-l10n-uk' has no installation candidate

I edited the file /etc/apt/sources.list, modifying the reference to buster to testing and added contrib non-frree, giving:

deb http://mirror.ox.ac.uk/debian/ testing main contrib non-free
deb-src http://mirror.ox.ac.uk/debian/ testing main contrib non-free

To reflect the change I action

apt update

Trying once more with the install and getting the now usual no installation candidate error.

I also replicated the reference to the testing distribution, adding two comparable lines for experimental.

As before I actioned an update and tried to do the installation. Another installation candidate error.

Looking at the Debian wiki page for Firefox it suggests using the unstable distribution.

I added this to the sources.list file:

deb http://mirror.ox.ac.uk/debian/ testing main contrib non-free
deb-src http://mirror.ox.ac.uk/debian/ testing main contrib non-free

deb http://mirror.ox.ac.uk/debian/ experimental main contrib non-free
deb-src http://mirror.ox.ac.uk/debian/ experimental main contrib non-free

deb http://mirror.ox.ac.uk/debian/ unstable main contrib non-free
deb-src http://mirror.ox.ac.uk/debian/ unstable main contrib non-free

Success! I now had the regularly update Firefox version installed.

Firefox as opposed to Firefox-esr can be installed on Debian via the repositories with a simple change to the sources.list file and acouple of command line actions.

Force Browser to Reload Cache From the Website

After updating a website, visitors see it as broken because their browser continues to reference the older JavaScript, JQuery and CSS files.

How to force the browsers of website visitors to make use of the newer updated support files?

Testing a website yourself its possible to refresh the browsers cache.

But for the visitor to your website this approach isn’t possible. What’s needed is for the website to tell the browser to forget the files which it has previously cached.

If its one or two files in the header or footer its possible to add an extension. But this is good for a one-off change, or at the end of a series of work, perhaps a major site update.

For example

<script type=’text/javascript’src’/jquery.js?ver=1.9.3’></script>

Note the added version number.

Changing the version number will cause the browser to get the revised file.

I’ve used this technique on images before where the image amendment, a rotation wasn’t being shown. On this occasion I added a parameter based on the edit time and date of the image.

For a website, such as WordPress, it may not be so easy to modify a file like this. If we have a child thime in use, is it worth copying the header file just to make this change?

Apache .htaccess file

For this method we’ll make use of mod_expires.

In the htaccess file make use of modexpires add the following to your .htaccess file located in the root of your website files.

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
ExpiresByType text/html "access plus 60 seconds"
ExpiresByType image/x-icon "access plus 60 seconds"
ExpiresByType image/gif "access plus 60 seconds"
ExpiresByType image/jpeg "access plus 60 seconds"
ExpiresByType image/png "access plus 60 seconds"
ExpiresByType text/css "access plus 60 seconds"
ExpiresByType text/javascript "access plus 60 seconds"
ExpiresByType application/x-javascript "access plus 60 seconds"

Include as many entries as you deem necessary, and change the time out as appropriate. I used the above rather short value so my client’s browser would reload the files, having been used heavily viewing recent changes.

The time option is given as a number plus the type, which can be:

  • seconds
  • minutes
  • hours
  • days
  • weeks
  • months
  • years

Page Header Meta Entries

Also there are entries for the top of the page header.

These can be added to the <head> section of the website file.

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

For a WordPress website I added them via the functions.php file. I didn’t want to go modifying the header.php file of the theme. The child theme didn’t have a copy, so why add one purely for this and also the theme had a header builder.

function vntweb_header_metadata() {
// Post object if needed
// global $post;
// Page conditional if needed
// if( is_page() ){}
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
add_action( 'wp_head', 'vntweb_header_metadata' );

One advantage with the use of the functions.php file is that a date test could be added. After, for example a week the addition of the meta entries could be removed.

It’s also possible to create a functions.php file to be added to each website development ,with a number of functions, enabling those which are required on a given website.

Other Options

Another approach is to use regular expressions to amend files. But this may presuppose that extensions do already exist. also looking for a simple modificatin, which isn’t prone to misinterpretatin. can be easily copied and used without the risk of doing damage I prefer the two solutions given above.


Inmotion hosting – apache mod expires

Stackoverflow – control web page caching

Mozilla – headers cache cotnrol

SQL add a Default to an Existing Table Column

When a previously created database table requires the addition of a default value. Can the amendment be made easily? And without recourse to the SQL Configuration Manager.

I had configured a database table. Subsequent testing showed that one of the fields required a default value.

I was testing for a value of less than 0, but there was an occasion where this field may not be given a value.

The use of a default value on the field would ensure a minimum base value for use in comparisons.

For ease I wished to implement the change through the website’s admin SQL page.

SQL add default to existing table column using DNN SQL console

I was using DotNetNuke which supports this. Your website might support something similar, or perhaps write a one-time use piece of code, or action through another SQL interface.

ALTER TABLE fruit ADD default ((-1)) FOR qty

In the example above I am amending the table called fruit and assigning a default value -1 to the qty field.

Apple Mail SSL Certificate Trust Warning

Mail server changes may result in an Apple Mail SSL certificate trust warning.

Some email client programs, such as Thunderbird, gmail and kmail, give the ability to permanently accept the warning and continue as normal.

However, Apple Mail does not permit this certificate trust warning to be ignored, or addressed as a valid exception.

Similarly Microsoft Outlook may permit a temporary security exception, but may not permit a permanent exception.

It is possible to workaround this warning IF you trust the new SSL certificate. The error message will give details that can be used to help you decide if you trust the certificate or not. The workaround is to reference the mail server by its hosting configured name, rather than the domain name.

I used a terminal program to get the IP address of the mail server

dig mail.example.com

and then took the IP address to look up its name


An entry such as mail62.example.co.uk was given.

This entry could then be used in place of the website domain in the configuration of the incoming and outgoing mail servers.

Outlook Fails to Remember Security Certificate Exception

Adding an email account to Microsoft‘s Outlook email client program I was getting an error when the connection to the server was made.

There was a security exception. The certificate doesn’t match the domain which I’ve entered. Did I wish to accept it?

I am able to confirm the security exception and download the certificate from the mail server. I can chose to save it either locally or globally.

For the remainder of that day I had no further error messages and the connection to the mailbox continued to work, both sending and receiving emails.

However, next time when I restart the computer it’s all the same once more – deja vu! Outlook once more states the error, requiring the certificate to be downloaded again.

Outlook had not permanently saved the exception.

Is there a means to ensure that Outlooks remembers the certificate security exception?

I was unable to find documentation which showed this to be possible.

This does raise the question:

Why am I still seeing the certificate error message, given that I have already downloaded and set the exception?

I had configured Outlook with an email account for a domain hosted on a generic mail server.

The mail server is used to host lots of domains. Some of its configuration settings are therefore generic, not specific to one of the hosted domains. An example of this is the SSL certificate. Whenever I start the computer and open Outlook afresh I get an error message relating to the certificate being invalid.

The cause of the error is the certificate, it is a wildcard certificate for a domain, allowing it to be applied across a number of mail servers.

However, this is specific to the hosting infrastructure and doesn’t match the individual domains which are being hosted.

As I was configuring the mailbox to use a generic mailbox with representation for a domain I chose to configure the incoming and outgoing email server by its generic reference, which matched the domain given in the security certificate.

With this change made all was well. Now when I start the computer and open Microsoft outlook there is no error message reporting that the security certificate doesn’t match the domain.

To find the reference for the mail server I used the DNS dig command to get the IP address. For example

dig mail.example.com

I was then able to use the nslookup command to derive the name of the mail server from the IP address. For example:


Setting a Custom 404 Page with htaccess

I bought a custom HTML website template with a 404.html page. How do I use it?

If I enter a wrong website address I don’t see the 404 page my browser simply shows a generic message from the hosting control panel.

The server needs to be configured to tell it what to do with when a page doesn’t exist.

The changes can be made in the .htaccess file found in the root of the public website.

Changes can be made either by FTP or via the file manager within the hosting control panel.

Often the file view begins one level down. Look for a directory called public_html, or similar.

In the .htaccess file add the following

ErrorDocument 404 /404.html

where 404.html is amended according to your error file name.

But this doesn’t work fully.. The error page is now shown as wished, but the address stays with the wrongly entered page.

What is required to complete is to redirect to the 404.html page. For this we’ll use the redirects.

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.html [R=301,L]

The above is added to the .htaccess file.

  • The first line turns on the redirects.
  • The following two lines set the rewrite conditions, checking for an existing file and directory respectively
  • Lastly the setting of the rewrite rule which takes the visitor to the 404.html page located in the root of the website.

Speech-dispatcher Using Legacy Directory in /var/run

With an update of Debian packages there was a message related to the speech dispatcher.

The older version of the program used the directory /var/run/speech-dispatcher, whilst this version 0.8.8-8 was looking to use the directory /run/speech-dispatcher

Given below is the relevant lines from the apt upgrade, relating to speech-dispatcher.

Setting up speech-dispatcher (0.9.0-5) ...
[speech-dispatcher.conf:1] Line references path below legacy directory /var/run/, updating /var/run/speech-dispatcher → /run/speech-dispatcher; please update the tmpfiles.d/ drop-in file accordingly.
[speech-dispatcher.conf:2] Line references path below legacy directory /var/run/, updating /var/run/speech-dispatcher/.cache → /run/speech-dispatcher/.cache; please update the tmpfiles.d/ drop-in file accordingly.
[speech-dispatcher.conf:3] Line references path below legacy directory /var/run/, updating /var/run/speech-dispatcher/.speech-dispatcher → /run/speech-dispatcher/.speech-dispatcher; please update the tmpfiles.d/ drop-in file accordingly.
[speech-dispatcher.conf:4] Line references path below legacy directory /var/run/, updating /var/run/speech-dispatcher/.cache/speech-dispatcher → /run/speech-dispatcher/.cache/speech-dispatcher; please update the tmpfiles.d/ drop-in file accordingly.
[speech-dispatcher.conf:5] Line references path below legacy directory /var/run/, updating /var/run/speech-dispatcher/log → /run/speech-dispatcher/log; please update the tmpfiles.d/ drop-in file accordingly. 

The file in questions is


Below are the old file contents of this file

d /var/run/speech-dispatcher                            0750 speech-dispatcher audio -
d /var/run/speech-dispatcher/.cache                     0750 speech-dispatcher audio -
L /var/run/speech-dispatcher/.speech-dispatcher         -    speech-dispatcher audio - /var/run/speech-dispatcher
L /var/run/speech-dispatcher/.cache/speech-dispatcher   -    speech-dispatcher audio - /var/run/speech-dispatcher
L /var/run/speech-dispatcher/log                        -    speech-dispatcher audio - /var/log/speech-dispatcher

And once more the revised contents of the file /usr/lib/tmpfiles.d/speech-dispatcher.conf

d /run/speech-dispatcher                                0750 speech-dispatcher audio -
d /run/speech-dispatcher/.cache                         0750 speech-dispatcher audio -
L /run/speech-dispatcher/.speech-dispatcher             -    speech-dispatcher audio - /var/run/speech-dispatcher
L /run/speech-dispatcher/.cache/speech-dispatcher       -    speech-dispatcher audio - /var/run/speech-dispatcher
L /run/speech-dispatcher/log                            -    speech-dispatcher audio - /var/log/speech-dispatcher

Apple Mac email add Local Subfolders

I like to store email locally, divided between personal and work email.

Copying emails locally allows me to set my email to delete the older emails from the server. Keeping me below the restriction on the mailbox

For work emails I use sub folders to divide up my administration and the different projects.

Using Thunderbird, this is easy to implement: simply create additional sub-folders below the Local Folders.

The aim is to replicate this using the Apple Mac email program

Apple Mac Email add Subfolders: Side Menu

In the image below can be seen a part of the side menu for an Apple Mac email program.

Added to this is the smart menu for the domain VNTweb.

Apple Mac Email add Subfolders: add new Folder

Additional sub folders can be added below the smart mailbox.

To add a new folder, or Mailbox as Apple calls it, hover over the mailbox to show the circled plus icon. Click on this icon to show a dialogue allowing the location to be selected and a name given for this new mailbox.

For the new top level mailbox/sub folder I left the location alone and
entered the name “Projects“.

I then added two new sub folders/mailboxes below this. You may wish to select Projects as your location, of maybe like me drag the Customer 1 mailbox below Projects by dragging it into the Projects folder.

Now to test the use of this mailbox.

In your Inbox pick one of your existing emails. Drag it into the Customer 1 mailbox. Keep the command button down to copy rather than move.

I checked that the email was still available from another computer and email program.

I then deleted the email from the inbox. Unfortunately both emails were now gone.

I was able to drag an email into the new sub-folder mailbox. It would then disappear from the inbox. If I copied the email to the mailbox, deleting it from either mailbox also deleted it from the other.

I considered the use of a Mailbox as opposed to a smart mailbox

For this I clicked on the Mailbox menu entry, across the top menu. From the dropdown menu I selected New Mailbox.

Apple Mac Email add Subfolders: New mailbox

From the familiar New Mailbox dialogue I chose On My Mac as the location. Adding a Mailbox name of Projects.

Under the Smart Mailboxes I now had a new section.

Apple Mac Email add Subfolders: Smart Mailboxes - On My Macon-my-mac

I was able to crate new sub mailboxes as I had done previously.

Of particular interest I found that emails copied into these sub folders/mailboxes were more permanent. They didn’t disappear if I deleted them from the inbox

By adding a simple Mailbox to the On My Mac location, with appropriate sub Mailboxes I was able to copy emails into this directory structure. This allowed me to save and group emails related to projects, incorporating both sent and received emails. Emails copied in this way were immune to the deletion of the original in the inbox.

Don’t forget to send yourself some test emails so that you can confirm that this is working for you. Software development has a habit of making changes which alter our previous experiences.