Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts

Monday, 4 February 2008

Asp.Net Ajax Calendar Extender

There is a bug with the AJAX calendar extender in that the style of the popup calendar are not applied if the text-box /calendar extender are hidden when a page first loads.

e.g. Panel with Details on is only shown once valid record found; if the first calendar extender on the page is within this hidden Details panel the calendar will not be displayed correctly when Details does become visible:

image

To fix this have a hidden calendar extender at top of the page:

<!-- Workaround for Calendar not displaying correctly - if hidden when page first loads -->
<div style="display: none"><asp:TextBox runat="server" ID="textbox1" /><cc1:CalendarExtender ID="ceTextBox1" runat="server" TargetControlID="textbox1" /></div>


Calendar is then displayed correctly:



image

Thursday, 13 September 2007

FileUpload not working ~ no state information on postback

Had a problem where the 'selected file' information was not coming through for a dynamically created FileUpload control. The problem was due to the FileUpload control being inluded on a Ajax UpdatePanel.

FileUpload control will not work with an async postback (Ajax UpdatePanel) because the details of the file to upload are included in the Web Request of a full postback.

See Eilons Liptons Blog for more details.

Solution was to have a dedicated upload page.

Monday, 3 September 2007

Validation of viewstate MAC failed... using AJAX UpdatePanel

Was getting the following error after a partial update of a component on an AJAX UpdatePanel:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster

It seems the problem occurs because after the partial update the component include a GridView that used DataKeyNames. The use of DataKeyNames requires that view state is encrypted.
I think the error occurred because this encryption was only taking place after the partial postback.

The solution seems to be to always have view state encrypted ~ a page directive.


viewStateEncryptionMode ="Always"

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.