Skip to main content

Posts

Showing posts with the label Javascript

Using JavaScript to update content in UpdatePanel

One of my recent pages needed to have a client side JavaScript function to select all items in a given multi select box. An event was wired to fire (to submit and update UpdatePanel) when one of these items were selected. This was working fine when selection was done by the end user using a mouse/keyboard. However, when I used a JavaScript function to select all items, the event was not firing. I had to fire it myself which basically meant that I had to submit the form (asynchronously). Here is what I did in my JavaScript function that was selecting all the items in a given select box to submit the form to update the contents in UpdatePanel. function SelectAll(objectId, submit) {     if (objectId) {        var str = '#' + objectId + ' *' ;        $(str).attr( 'selected' , 'selected' );     }     if (submit) {      var prm = Sys.WebForms.PageRequestManager.getInstance();    ...

Asp.NET AJAX client reference

When working with AJAX in .NET environment you may need to at times control UI components at the client side through JavaScript. There are a lot of things you can accomplish on the client side using the provided JavaScript API. Here is a link to the Asp.NET AJAX Client Reference . I recently used AjaxToolKit in one of my applications. I made heavy use of Tabs . In one of my pages, I needed to make sure that users could not click on the second or the third tab without saving a form that was in the first tab. I needed some sort of a validation to enforce this. I handled this on the client side since JavaScript is required for the application. Tabs has an attribute called OnClientActiveTabChanged. This attributes allows you to set up a client side function that gets executed when a tab is clicked. Here is how this function looked in my example: function validateQuestionsAndAnswers(sender, args) { var tabIndex = sender.get_activeTabIndex(); switch(tabIndex) { case 1: ...

Using jQuery to handle confirmation of navigating away from HTML Forms in edit mode

On my recent project, I had a requirement that stated that I needed to warn the end users when they tried to navigate away from an HTML Form that they started editing. The warning message was to indicate that they were leaving and they forgot to hit the submit button. There are many ways for end users to navigate away from a given HTML Form. They could click a link within the application, they could close the browser, or type in a new URL. This solution focuses on clicking available links on the application they are on. For this solution I used jQuery. I am a big fan of jQuery and I use it whenever I can. The solution basically involves tracking user activity when they are working with an HTML Form. By tracking I mean to capture their actions when they click/focus on HTML form elements such as input, select, textarea, radio, and checkbox. Here is the code that handles all this: var somethingChanged = false; $(document).ready(function() { handleReady(); }); function handleReady() { ...

Limitations of Ajax

If you do not know the term "AJAX" you should not be reading this post. This post assumes that you have worked with AJAX in the past before. I use AJAX a lot with my applications. I ran into some limitations over the years with AJAX. I thought it would be a good idea to list these limitations and how I was able to overcome them.As many of you know, AJAX is a solution that allows our applications to communicate asynchronously. Due to the nature of asynchronous communication, web browsers partially update contents on a given page. When back or forward buttons are used, the pages in question will not go back or go forward to the its updated/initial state. A similar problem will exist with bookmarks. Since the content is updated with the same url, the state of the page is lost to be saved. One way to overcome this limitation is to use a framework called RSH . This framework basically allows you to manipulate web browsers history object. It allows you to store state information wi...