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

Sunday, 6 May 2012

Deserialize json object with a date time to a c sharp oject

If you want to deserialize and object that has been serialized with the JavaScriptSerializer and it contains a date time object then you may run into a parser / format error for the date time. this can be fixed by doing a replace on the string before deserializing.

Tuesday, 7 February 2012

How to fire an async postback from javascript

Thursday, 12 January 2012

Restoring focus to a control after an UpdatePanel Update

Using Ajax update panels can sometimes cause issues with restoring the focus of the control after the update panel updates.

This can be achieved with a little jQuery and hooking the begin and end request events of the PageRequestManager.

Monday, 21 March 2011

How to open a window from a button in an update panel

If you have a control in an update panel and you dont want to add the whole control as a postback trigger ( if you are using a gridview and want one partiular row command to open a window for example ) then you can achieve this with the following code.

Saturday, 9 October 2010

Ajax ComboBox Object reference not set to an instance of an object.

I was getting the following error after completing an operation in a web application and trying to click a link to enter a new Invoice on the same page.

This turned out to be due to one of the combo boxes trying to load its postback data (because I was navigating to the same page). The reason the error was being thrown is because I disabled the controls on the form and if they are disabled then the Ajax Combo box cannot load its post back data.

One work around would be to Response Redirect to another page after the invoice is posted. This way the controls would not try to load postback data again.

Removing the method to disable the controls also stopped the issue so replacing the combo box with a text box was a simple work around.

Just to re iterate its the control being disabled that has caused the problem when the control is trying to load the postback data.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:





An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:





[NullReferenceException: Object reference not set to an instance of an object.]
   AjaxControlToolkit.ComboBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +106
   AjaxControlToolkit.ComboBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +36
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +693
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743

Friday, 17 September 2010

Uploading Files using FileUpload control in Update Panel in ASP.Net AJAX

If you have ever tried to use a FileUpload control inside an update panel you may find that it does not work or does not contain a file name. This is by design to avoid security holes where a file could be uploaded without you knowing. There is however a work around for this by making the upload button perform a full post back.

ASP Markup

Code Behind

Thursday, 16 September 2010

Ajax - 'sys' in undefined and the ASP.NET Ajax client-side framework failed to load

I had been struggling with this issue for a couple of days now. A small warning icon appears in Internet Exporer. Clicking on it shows a number of error messages.

1 - ASP.NET Ajax client-side framework failed to load
2 - 'sys' is undefined

I had checked the web.config file multiple times, all required sections were present and referencing the correct .net version dlls.

Finally after double checking absolutely everything I noticed that one of the handlers the web config was referencing did not have an extension mapping. This was the .axd extension. I added this in to IIS but the problem still occurred. Checking the handler mapping again I unchecked the 'Verify that the file exists' check box and retried the web page. This time it worked!

So in conclusion it turns out you do need to have the .axd extension mapping if it does not exist. And the check box to 'Verify the File Exists' must not be checked.

Thursday, 9 September 2010

How to make Ajax Calendar Extender cause postback on selection

Here is an example of how to make an Ajax Calendar extender caused a post back after a date is selected. In this example a label will be updated with the date that is selected in the calendar extender.

aspx:

code behind: