Friday 15 June 2007

Problems with Properties showing in Property Editor with custom web server controls

I was creating a custom web sever control which was inherited from CompositeControl, I had removed a couple of editor properties, I then noticed that some properties were not being shown in the property editor after you switched between source and design view of a web page. To fix this I had to add in a new property, compile and use it, then take the new property back out again.
I also had to take the reference of the object out of the web page and stick it back in again.
All in all a pain in the bottom, and a waste of time!

Dear MS why did you make the development of web controls so annoying, like having to put a new control on the screen everytime you make a change, and debugging the component in design mode what were you thinking!

Thursday 7 June 2007

NHibernate:object references an unsaved transient instance

"object references an unsaved transient instance" recieved when performing a save (and transactional commit).
Caused by a related (parent) record not being saved and the entity not set up for cascading save.
e.g. User record has link to Person record but when user is saved the linked person is not saved.
Solution is either to turn on cascading saves for related entity or to explicity save the related record by creating a business object method.

Tuesday 5 June 2007

Ajax Extender Properties Gotchas

When you want to add a property to an Ajax Extender you need to do the following.

Make sure you have installed the Ajax Extender Templates, run AjaxControlExtender.vsi from the AjaxControlExtender directory of your toolkit install.

Create a new item using the ASP.NET Ajax Extender Control Template from my templates.

Note : If you set the namespace to have a . in it e.g. Company.AjaxControls then the Javascript will not be able to find the script as a webresource. If you want to do this then you have to manually change the ClientScriptResource attribute of the extender.


1) Create the C# Property in the controlExtender.cs file

[ExtenderControlProperty]
[RequiredProperty]
public string ExampleControl
{
get { return GetPropertyValue("ExampleControl", ""); }
set { SetPropertyValue("ExampleControl", value); }
}

2) Create the JavaScript Property in the controlBehaviour.js file
  • In the function(element) section, at the top of the page by the todo 1 to declare the property on the JavaScript side

    this._ExampleControl = null;

  • Add the property getter and setters at the bottom of the file

    get_ExampleControl : function() {
    return this._ExampleControl;
    },

    set_ExampleControl : function(value) {
    this._ExampleControl = value;
    },
Note : The getter and setters are named get_(propertyname) and set_(propertyname). the asp.net Ajax controls expect the names in this form.