Archive

Archive for the ‘Technical’ Category

Example of Bootstrap Dropdown menu in Kendo Grid

August 21st, 2015

After some trial and error I got a bootstrap dropdown menu working in a Kendo grid using code like this:

<blockquote>columns.Bound(theitem => theitem.ID).ClientTemplate
(“<a href=’/” + @”\#” + “/Items/Items_Update/” + “#=ID#” + “‘ class=’btn btn-xs btn-info’ rel=”nofollow”><i class=’icon-pencil’></i></a> ” +
“<div class=’btn-group’>” +
“<button type=’button’ class=’btn btn-default btn-xs dropdown-toggle’ data-toggle=’dropdown’>+<span class=’caret’></span></button>” +
“<ul class=’dropdown-menu dropdown-menu-right pull-right’ role=’menu’>” +
“<li role=’presentation’><a role=’menuitem’ tabindex=’-1′ href=’/” + @”\#” + “/Items/Items_Update/” + “#=ID#” + “‘ rel=”nofollow”>Edit</a></li>” +
“<li role=’presentation’ class=’divider’></li>” +
“<li role=’presentation’><a role=’menuitem’ tabindex=’-1′ href= ” onclick=’window.open(\”Items/OutputPDF/” + “#=ID#” + “\”” + “,\”_blank\”);return false;’ rel=”nofollow”>Download</a></li>” +
“</ul>” +
“</div>”
).Filterable(false)
</blockquote>

Now, I can show a Kendo grid/ list and have a dropdown menu on each row in the grid that I can use to take actions on grid items.

InstallShield Express Major Upgrade

April 22nd, 2015

I’ve switched to Installshield 2014 Express as my installer package of choice. I was using an older Premier version that mysteriously broke and looked around for other installer packages. Eventually however, the dependency management and scanning capabilities of Installshield won me back and I purchased Installshield Express as I only wanted to produce Simple MSI installers.

To produce a new installer in Installshield Express I needed to force a major upgrade to uninstall any older versions produced using my old installation package. After some experimentation to ensure that any later installer produced with Express could also upgrade older Express installers, I decided I would always use a major upgrade for every installer version I produced from then on. Other than including the relevant files and so on in the InstallShield project there are 5 key items you need to take account of when producing a major upgrade:

1. The product version number.

You need to increment this for each new installer you produce.

2. The Product Code.

This needs to change for every new installer you produce.

3. The Upgrade Code.

This should remain unchanged AND should match the Upgrade Code for any pre-Express installer.

4. The Package Code .

This needs to change for every new installer you produce.

5. Add an Upgrade Path to the Project if you don’t have one already

Dealing with these items one by one …

1. Product Version Number

In the Installation Designer, click Organize Your Setup->General Information, then enter your new Product Version Number.

product-version-number-organize-your-setup

2. The Product Code

In the Installation Designer, click Organize Your Setup->General Information, then click the {…} button in the Product Code row.

product-code-organize-your-setup

3. The Upgrade Code.

DO NOT CHANGE THIS!

upgrade-code-organize-your-setup

4. The Package Code

In the Installation Designer, click Releases, then click the Express node in the middle panel and click the {…} button to generate a new Package Code.

releases-package-code

5. Make sure you have an Upgrade Path …

In the Installation Designer, if you haven’t already done so, click Organize Your Setup->UpgradePaths then in the middle panel, right-click Upgrade Paths and add new path.

In the new upgrade path, enter the min and max versions. You can leave the min version blank but still set Include Min Version to Yes. Set the Max Version appropriately to limit the versions the installer will upgrade.

upgrade-path

Then build the installer and run. The installer should then uninstall any previous version of the software with the same package code whether the old installer was created with an older InstallShield or with InstallShield Express.

For help with major upgrades in other versions of InstallShield, see: http://www.sliqtools.co.uk/blog/technical/installshield-major-upgrade/

and

http://www.sliqtools.co.uk/blog/technical/installshield-major-upgrade-two-entries-in-add-remove-programs/

SQL Server Express: Login failed for user X: Error 18456

July 20th, 2014

After creating a new SQL server login with a password in SQL Server Management Studio and then adding a user with the same name as the login to a database, I was having a lot of trouble getting my code first entity framework model to connect to the database. Every time I tried to specify the connection for a context then get a list of objects from the context, I got a SQL exception indicating that the login/ password did not work and could not be logged into the database.

After some research, I found that by default SQL Express only works with Windows Authentication for logins and you have to configure the server to work with both Windows Authentication and SQL Server logins with passwords. To access the configuration setting, right-click the topmost tree node (the server name) in SQL Server Management Studio and show the Server Properties.

In the Server Properties dialog, click the Security settings node in the Select a page panel, then under the Server authentication settings, check the SQL Server and Windows Authentication mode. Then press OK to close the dialog.

sql-server-properties

To get SQL Server Express to pick up the new setting you need to stop and start the server. To do this, again right-click the server name in SQL Server Management Studio and choose Restart from the popup menu. OK and dialogs that come up asking for permission to restart the server. You should then be able to create a connection string to use with an entity framework context using the server name, login/ user id and password you have set. The connection string will be of the form:

Data Source=<server name>;Database=<Database name>;User Id=<Login>;Password=<Password>

Configuring Email Read Receipt Options in Outlook

June 30th, 2014

Microsoft Outlook allows you to configure options for how read receipt requests are handled. When you receive an email for which the sender has requested a read receipt you can configure Outlook to ignore the read receipt request, always automatically send a read receipt or ask you email by email whether to respond with a receipt or not.

To configure the read receipt options, choose the Options option in the Tools menu.

The, in the Outlook Options dialog, choose the Email Options … button near the top of the Preferences tab.

outlook-email-options

In the Options dialog, then press the Tracking Options … button.outlook-email-tracking-options

Finally, in the Tracking Options dialog, choose the desired option before pressing the OK button.

outlook-ask-for-read-receipt

For more Outlook tips, see Configuring the Default Email Account in Microsoft Outlook.

ASP.NET MVC : Accessing String Resources in CSHTML files

April 26th, 2014

When writing web pages in ASP.NET MVC, the standard way of outputting label names is often unsatisfactory as you end up with a label that follows a variable name, e.g. including a line like:

@Html.LabelFor(model => model.PadNumberLength)

ends up showing a label:

PadNumberLength

where you really want:

Pad Number Length

There are a number of other ways of changing the label, e.g. you could put a DisplayName attribute on the property in the model, e.g.

[DisplayName("Pad Number Length")]
public int PadNumberLength { get; set; }

However, especially if you have come to ASP.NET MVC programming from a desktop environment such as Winforms or WPF, the most natural way to get a label name is from a resource file. This also makes it easier to localise your pages in the future.

An ASP.NET MVC project contains a Resources file under the Properties node in the solution explorer. You can put all your string resources in this file. To access the resources in a CSHTML file, include the following HTML helper in your solution:

public static MvcHtmlString ResourceString<T>
    (this HtmlHelper<T> html, string ResourceName)
{
    var Manager = new ResourceManager(typeof(Properties.Resources));
    return MvcHtmlString.Create(Manager.GetString(ResourceName));
}

This means you can then write labels such as:

<label>@Html.ResourceString("PAD_NUMBER_LENGTH")</label>

that output the resource strings from your Properties.Resources file.

Easy Way of Examining Exception Details in Visual Studio

April 16th, 2014

When an exception is raised while debugging an application in Visual Studio, a dialog like the following appears showing a number of options to get more detail on the exception, e.g. the stack trace and line number on which the exception occurred:

One way of digging into the exception to find out more details is to click on the View Detail … link in the dialog. This shows a watch window like view that lets you tunnel into the exception fields.

However, an easy way of scanning all the exception details, is to click the Copy exception detail to the clipboard option, then paste the copied data into Notepad. You then get all the available exception details in a form you can easily scroll through or even search.

How to Fix a Hacked Website – Hacked by r00t3xpl0i7

November 4th, 2013

Coming back to one of my WordPress blogs at the weekend I had a nasty surprise. The website was showing the page below indicating that the site had been hacked.

hackedwebsite

To try and see how this could have happened, I attempted to log into the wordpress admin account by going to the URL: www dot mydomain dot com/wp-admin/. What was really surprising was that I could not log in as admin even though the correct WordPress login page was still visible in the wp-admin subfolder.

Fortunately, I was able to log in to the cPanel for the site through the hosting company’s main website and using the File Manager in cPanel, I began to look for any suspicious files or changes. ¬†As I was unable to log in to the WordPress site, I knew I also had to check the passwords in the WordPress MySQL database.

To correct the password, I opened up the WordPress MySQL database using PHPMyAdmin and looked at the admin password and email address in the wp_users table. I found that the email address wasn’t mine – it had been changed. I edited the email address back to mine using PHPMyAdmin and cleared the password field:

wordpress-wpusers

I then went back to the WordPress login page on my site (www dot mydomain dot com/wp-admin/) and clicked the Forgot password link and followed the instructions to set a new password. To be on the safe side I set a very strong password. Having done that I could then login OK to the WordPress control panel.

However at this point, the website was still showing the hacked page. Going back to File Manager in cPanel and looking through the PHP files, I found that the index.php of the WordPress theme (in the wp-content/themes/theme name/ folder had a very recent modified date. Opening up the index.php for viewing showed that the file had been overwritten and now contained PHP to show the hacked page. Unhacking the site was then easy – I logged into the WordPress control panel and switched themes – the site was then back fully functioning. To be on the safe side, I deleted the hacked theme in the WordPress control panel. At this point I’m assuming the hack was due to a weakness in the PHP for the WordPress theme as the password was pretty obscure. However, I’ll be monitoring the WordPress blog to see if the site goes down again.

Kendo UI Grid: Custom Edit Button for Ajax Grid

September 21st, 2013

While trying to display a list of data in a Kendo UI grid for which the data was loaded via Ajax, I wanted to have a custom command that loaded a new page to edit a row. In the specific case I was looking at, I didn’t want to edit inline or edit the row data in a popup dialog – I wanted to leave the page showing the grid and load a new HTML page to do the edit.

The project I was working on used ASP.NET MVC and the handy Kendo UI MVC wrappers. The key to loading a new page was inserting a clickable link that could call a controller action and pass in the ID of the row to edit. To keep things consistent, I also wanted my link to look like a normal Kendo UI grid edit button.

While I could find examples of how to include custom links when a Kendo Grid was server bound, finding out how to do the same things for an Ajax bound grid was more difficult. In the end I found that specifying a column template like this worked:

columns.Bound(invoice => invoice.ID)
   .ClientTemplate
      (@Html.ActionLink
          ("<span class='k-icon k-edit'></span>Edit",
           "Edit",
           new { ID = "#=ID#" },
           new { @class = "k-button k-button-icontext" }).ToHtmlString());

Note that the first argument to the Html.ActionLink call is usually used to give the text of the link but I also included a span in order to add the correct Kendo CSS classes to make the link look like a button with an edit icon.

The result of the above client template for a column in a Kendo grid is that an edit button like the following is displayed:

kendo-ui-edit-button

and when the button is pressed, the following controller action is called:

/Invoices/Edit/3

assuming that the controller for the grid is the Invoices controller and that the row ID (or primary key of the record for the row) is 3.

System.Web.Mvc.HtmlHelper does not contain a definition for Kendo

July 5th, 2013

While trying to add the KendoUI jQuery framework to an existing MVC project I cam across the following error when loading a page that used the KendoUI Grid HTML Helper:

‘System.Web.Mvc.HtmlHelper<dynamic>’ does not contain a definition for ‘Kendo’

I should have realised I was going to get an ASP.Net runtime error for the page as the Razor intellisense couldn’t find the Kendo Grid helper either:

@(Html.Kendo().Grid

The problem stumped me for a while as the only help I could find on how to solve the problem was that I had to add the following to the namespaces in the web.config:

<add namespace=”Kendo.Mvc.UI” />

However, even after adding this namespace to the web.config, the same problem continued.

The solution to the problem became apparent when I noticed that there was more than one web.config in my project and I had added the namespace to the wrong one. I had added the namespace to the web.config in the root folder of the project but when I added the same namespace to the web.config in the Views folder the intellisense began to work and my Kendo UI grid worked OK. Here’s a pic. showing the location of the web.config file I had to edit in my Visual Studio 2012 project:

kendo-mvc-ui

and here is a pic. of the namespace reference added into the web.config:

kendo-mvc-ui-namespace

ASP.Net MVC Disable Cache To Keep Ajax Working OK

June 15th, 2013

After coming back to my ASP.Net MVC project where I was using the Html.DropDownList scheme I had written about earlier on this blog, I cam across a bug where my dialog containing the dropdownlist wouldn’t show the correct selected item. I could choose a new selected item and submit the form back to the server OK but on reloading the dialog, the first item in the dropdown was always selected. My initial though was that my example code was incorrect and that I needed to start hunting again to find out how dropdownlists really work. However, while debugging, I noticed that the controller action that was returning the partial view for the Jquery dialog containing the dropdownlist seemed to only run once. I had placed a breakpoint in the action and noticed that the breakpoint was only hit when the dialog was loaded for the first time.

I was loading the view into containing the dropdownlist into a Jquery dialog using a load call like this:

$(this).load("@Url.Action("CreateCustomer", "Customers")"

A little research found out that these type of Ajax calls can be cached by browsers. This explained why the load resulted in my action being called once but not a second time – since the IE browser had cached the response.

To get the partial view to load reliably, I ad to disable the cache. To do this I put an OutputCache attribute on the controller action as follows:

[OutputCache(Duration = 0, VaryByParam = "*")]
[HttpGet]
public ActionResult CreateCustomer()

This attribute could be applied at the controller level in order to disable caching for the entire controller:

[OutputCache(Duration = 0, VaryByParam = "*")]
 public class CustomersController : Controller

but for the specific problem I had, it works fine just being applied to my specific controller action.