Wednesday, June 11, 2008

PostBack the form when a value is selected from the results returned by autocomplete extender

Some times we would like to do a post back when we select a value from the results returned by the Autocomplete extender. To do this you can leverage one of the client side properties that the AutoComplete Extender exposes. The property is OnClientItemSelected which takes a javascript method name as value.

<asp:UpdatePanel runat="server" id="UpdatePanel1" >

<asp:TextBox ID="txtOrderNumber" runat="server"
AutoCompleteType="Disabled" MaxLength="5"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtender ID="OrderNumberAutoCompleteExtender"
runat="server" CompletionInterval="100" CompletionSetCount="20"
EnableCaching="true" MinimumPrefixLength="2"
ServiceMethod="GetOrderList" ServicePath="~/ASPX/Common/AutoComplete.asmx"
TargetControlID="txtOrderNumber" OnClientItemSelected="OrderNumberChanged" />


<Script type="text/javascript">
function OrderNumberChanged( source, eventArgs )
__doPostBack('<%=UpdatePanel1.ClientID%>', ''); //do a postback

Digg It! Add to Stumble This

AutoComplete Extender dropping leading zeroes from the values in the result set

The autocomplete extender in the AJAX Control Toolkit drops off the leading zeroes from the values in the returned result set. This appears to be a known bug in the Autocomplete Extender.

To rectify this problem, add single quotes to the value before adding it to the list either in your Web Method or Page Method that the AutoComplete Extender uses to load the results

In your web method or page method do the following.

resultList.Add("'"+result+"'"); //Single quotes are need as a work around for a known bug in autocomplete extender. Leading zeroes are dropped without quotes.

Digg It! Add to Stumble This

Monday, June 02, 2008

Check if a Child Window is closed using Javascript

The basic idea here is to have a javascript timer, that checks to see if the child window is closed. The setTimeout function in javascript takes a function as input and runs at a specified interval. In the function we give as input to the timer, we check to see if the popup window is closed, if closed do what ever you want to do if the popup is closed and stop the timer.

<script language="javascript">

var detailsWindowTimer;
var detailsWindow;

function OpenDetailsWindow()
detailsWindow ='../../UserDetails.aspx?UserID=1', ' 'UserDetails','directories=0,location=0,toolbar=0,status=1,menubar=0,scrollbars=1,resizable=1');
detailsWindowTimer = setInterval("WatchDetailsWindowForClose()",2000); //Poll
every 2 seconds to see if the details window is open or closed

function WatchDetailsWindowForClose()

if (!detailsWindow || detailsWindow.closed)

/// Do your stuff here....
clearInterval(detailsWindowTimer); //stop the timer

<a href="#" onclick="OpenDetailsWindow()">Details</a>

Digg It! Add to Stumble This