Skip to main content

Posts

Limit the characters in a multi row textbox

The maxlength property to limit the number of characters does not work on a multi row text box. We have to rely on custom JavaScript to limit the MaxLength functionality. Here is a snippet that does that. function ValidateCharCount(txtBox, maxLength,controlName) { var input; var length; input = txtBox.value; length = input.length; var allowedLength = new Number(maxLength); if (length > allowedLength) { txtBox.value = txtBox.value.substring(0, allowedLength); alert(" Only " + maxLength + " characters are allowed in the field " + controlName); txtBox.focus(); } } The function above takes three parameters. The first parameter is reference to the textbox control,second parameter is the max length of characters, third one is the textbox field description. The function kicks in once the texbox loses focus, alerts the user if the character count exceeded the allowed length and then truncates the characters to the a...

IF by Rudyard Kipling

I came across this beautiful poem by Rudyard Kipling which totally blew my mind away. The poem is simple to read and sums up the way one has carry himself in just a few stanzas. Here it is in its entirety. [IF] If you can keep your head when all about you Are losing theirs and blaming it on you, If you can trust yourself when all men doubt you But make allowance for their doubting too, If you can wait and not be tired by waiting, Or being lied about, don't deal in lies, Or being hated, don't give way to hating, And yet don't look too good, nor talk too wise: If you can dream--and not make dreams your master, If you can think--and not make thoughts your aim; If you can meet with Triumph and Disaster And treat those two impostors just the same; If you can bear to hear the truth you've spoken Twisted by knaves to make a trap for fools, Or watch the things you gave your life to, broken, And stoop and build 'em up with worn-out tools: If you can make one heap of all your...

Debug classic ASP in Visual Studio 2008 with SP1

At work we still have some classic ASP applications. Visual Studio 2008 did not support classic ASP debugging until SP1. Once you installed VS 2008 SP1, follow these steps to debug classic ASP. 1) Enable ASP server side script debugging in IIS a. To do this, launch IIS, right click on the virtual directory of your application, and click on properties from the context menu. Select the virtual directory tab from the properties windows. Click on the Configuration button in the application settings section. b. In the application configuration window, select the debugging tab and make sure that enable ASP server-side script debugging is checked 2) From your visual studio 2008, launch the classic ASP application by pressing F5. Wait for the asp page to show up in the browser 3) Once the application is launched, go to Debug --> Attach to Process to launch the Attach to process window. In that window, click on the Show Processes for all users checkbox to show all processes. 4) In the lis...

Adding custom client side validation to controls inside GridView

Some times we find it necessary to provide custom validation to controls inside a GridView. Recently I had to have a DropDownList for selecting a country inside a gridview, the country dropdownlist contains several items including an item with the text "Other". When "Other" is selected, a textbox should show up where in the user can provide the rationale for selecting "Other". Also, I had to make sure that the textbox is not left blank when "Other" is selected. To Recap Requirements: Make sure that a value is selected from the country dropdownlist. When "Other" is selected for country, show a textbox to show enter what the "Other" country is Make sure that a value is entered in the textbox when "Other" is selected First the GridView, for simplicity I'm just showing the country dropdownlist and the TextBox. Both those controls are included in a templatefield in the GridView Leaving out the databinding details. I a...

Find the cause of poor performance in Sql Server

I found the following two part article by Gail Shaw on Simple-Talk really helpful in trouble shooting poorly performing queries in Sql Server. The articles talks about spotting poorly performing queries with the help of the Profiler, understand Sql Server Query plans and fine tune the peformance using proper indexes. Part 1: http://tinyurl.com/ccl6gj Part 2: http://tinyurl.com/okcuqg

Validating checkbox list in asp.net using JQuery

ASP.net does not provide in built support to validate a checkbox list. We have to rely on custom javascript to verify if at least one checkbox in the list is checked. Since we cannot add a validator to the checkbox list, I usually put a dummy textbox on the form and add a custom validator to that textbox. <asp:CheckBoxList ID="cblLostDescription" runat="server" RepeatDirection="Horizontal" TabIndex="14"> <asp:ListItem Value="L">Lost/Stolen</asp:ListItem> <asp:ListItem Value="D">Destroyed</asp:ListItem> <asp:ListItem Value="M">Damaged</asp:ListItem> <asp:ListItem Value="O">Other</asp:ListItem> </asp:CheckBoxList> <asp:CustomValidator ID="custValDescrption" runat="server" ErrorMessage="Property Description is required" Display="Dynamic" ControlToValidate="txt...

Clear Validation Errors and Validation Summary messages

ASP.net built in validation does not provide us a straight forward to clear all the validation errors. This would be really helpful while resetting a form. The reset html button would simply reset the form values but will not clear the validation errors. The following javascript code snippet can be used to clear the validation error messages. Have a reset button on your form and call the following js function onclick. <input type="reset" onclick="HideValidationErrors();" /> function HideValidationErrors() { //Hide all validation errors if (window.Page_Validators) for (var vI = 0; vI < Page_Validators.length; vI++) { var vValidator = Page_Validators[vI]; vValidator.isvalid = true; ValidatorUpdateDisplay(vValidator); } //Hide all validaiton summaries if (typeof (Page_ValidationSummaries) != "undefined") { //hide the validation summaries ...

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" OnClientItemSelect...

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.

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 = window.open('../../UserDetails.aspx?UserID=1', ' 'UserDetails','directories=0,location=0,toolbar=0,status=1,menubar=0,scrollbars=1,resizable=1'); detailsWindow.focus(); detailsWindowTimer = setInterval("WatchDetailsWindowForClose()",2000); //Poll every 2 seconds to see if the details window is open or closed } function WatchDetailsWindowForClose() {...

Postback the updatepanel when an item is selected in AutoCompleteExtender

<asp:TextBox ID="txtOrderNumber" runat="server" AutoCompleteType="Disabled" MaxLength="5"></asp:TextBox> <ajaxToolkit:AutoCompleteExtender ID="OrderNumberAutoCompleteExtender" runat="server" CompletionInterval="100" CompletionSetCount="20" ContextKey="region" EnableCaching="true" MinimumPrefixLength="2" ServiceMethod="GetOrderNumberList" ServicePath ="~/ASPX/Common/AutoComplete.asmx" TargetControlID="txtOrderNumber" UseContextKey="true" OnClientItemSelected="OrderNumberChanged" />

How to use ASP.net AJAX timer control to alert user when session times out.

Recently I needed a way to redirect the user to the login page after a certain time of inactivity. I found a neat way to do this using ASP.net AJAX timer control. Following is the approach I took. I put the code in my master page as it can be shared by all the content pages. 1) Drag and drop the script manager control. 2) Drag and drop an update panel. 3) Set the updatepanel's UpdateMode property to Conditional . 4) Drag and drop a Timer control inside the update panel. Set the Interval property to the session time out time. 5) Set the timer control as a trigger to the update panel which causes it to postback on some event (Tick) . Following is the code after the first 5 steps. <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanelMaster" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:T...

SharePoint: Comparing dates in XSLT

In one of my sharePoint projects, I had to compare a date with the current date in XSLT. As it turned out, there is no support for date comparision in XSLT. This is how I went about doing it. The trick involves converting the date string into a number Say the date is in ISO format YYYY-MM-DDTHH:MM:SSZ (for example, 2001-01-21T22:54:47Z). Say we have a variable DueDate <xsl:variable name="DueDate" select="'2001-01-21T22:54:47Z'"> Replace the dashes in the string with empty string Take the first 10 character in the date sring convert the string to number number(translate(substring(@DueDate,1,10),'-','')) On doing the above we get: 20010121 We can do the same thing with the date to compare. We can compare the duedate with the current date in SharePoint as follows number(translate(substring(@DueDate,1,10),'-','')) & lt; number(translate(substring(ddwrt:TodayIso(),1,10),'-','')) You can apply the same log...

Gandhigiri

Some of the Indians who were affected by the USCIS revised July bulletin staged a novel protest (Gandhigiri) by sending flowers to USCIS. Follow the links below for more details. http://www.ibnlive.com/news/immigrants-refused-green-cards-take-to-gandhigiri/44667-2.html?xml http://www.ibnlive.com/videos/44667/immigrants-refused-green-cards-take-to-gandhigiri.html

USCIS and the 485 Fiasco....

I hope by now most of the victims of July Visa bulletin have recovered. It is beyond any one's comprehension how USCIS could behave in such an irresponsbile manner. They had a freaking two weeks to issue a correction to the bulletin but they waited until they received the applications only to send them back. Forget about the expenses incurred during the 485 filing process, the long lines to get medical exams done and the time wasted to get all the paper work done, I heard stories of people cancelling their travel plans, returning from abroad, flying to the lawyers' offices to complete the forms etc. I wonder if USCIS deliberately rejected all the applications so that they could collect the hiked fee which increases 3 fold from August. After this stupid action I feel that the state department has no concern for immigrants' feelings.

Taste of Vista

I had a taste of Vista this weekend on my friend's laptop. I think Microsoft shot itself in the foot with their over protective security features. I'm pretty sure users will get exhausted with "Are you sure you.....? after some time. I dont understand why I have to confirm every time I open an application. Didn't M$ft think about how it will ruin the end user experience? My friend created a website in .Net and wanted to host it in IIS. To successfully host the website in IIS we had to go through a multi layered defense system. We overcame the first line of defense by turning on the IIS feature, which I think is good. Then came the second line of defense which is "No permissions to....." to which we did not have a straight answer. After spending some time on Google with no luck, we stumbled on the answer by chance. (We had to give IUSR account permissions on the physical directory that contains the website). I thought well this is the answer and tried to laun...

Parser Error Message: Access is denied

Some times while debugging a web application in Visual Studio, I run into error similar to the one below. The error does not go away even when Aspnet_wp.exe process is killed and IIS restarted. Parser Error Message: Access is denied It happens that the error message occurs when the Microsoft Index Server (Cisvc.exe) is running on your machine. Cisvc.exe holds a lock on the Temporary ASP.NET Files directory. For a quick fix, kill the Cisvc.exe. For a permanent fix exclude the temporary ASP.NET files directory from being indexed by the index server. More on the error can be found at MSDN .

Inida face early exit from the world cup

I was a bit down yesterday as India lost against Sri Lanka and are almost out of the world cup. But on putting the defeat in proper perspective, I realised that the Indian team is a bad team and bad teams are supposed to lose. It is immature to get emotional when a bad team loses. Now that India will not be playing any more, I can relax and just enjoy the game of cricket. That is what I'm doing right now. I'm watching South Africa chase Australia's mammoth total of 377 with great ease.

Getting Started with ASP.NET AJAX

I have been doing AJAX in ASP.NET for a while using frameworks like Anthem.Net and AJAX.net. I did not use Atlas as Atlas was still in development and more over our client has not upgraded to .Net 2.0 yet. I have started playing with Microsoft ASP.NET AJAX (formerly Atlas) for a week now. At first I was really overwhelmed with the whole Atlas documentation but felt a little comfortable after watching the Ajax videos on ASP.NET website . Here I will go through the process of getting started with Microsoft ASP.NET AJAX. You can access this post here on Google docs. http://docs.google.com/View?docid=dd8p9vd3_7dzckx7 Install MS AJAX Download and install Atlas from here.( http://ajax.asp.net/downloads/default.aspx?tabid=47 ) Visual Studio Tool Box After installing MS AJAX, you should see AJAX Extensions tab in the visual studio tool box. New ASP.NET project template A new project template that allows you to create ASP.NET AJAX enabled Web applications is also installed on installing Atlas. ...

Attended Windows Vista and Office 2007 launch

Today I attended Windows Vista and Office 2007 launch in Washington D.C. The event took place in Washington Hilton hotel. I was really impressed with some of the new features in Windows Vista like the new dazzling interface, flip 3d windows, fast search, gadgets, parental controls etc. The menus in Office 2007 are replaced by what Microsoft calls ribbons. There are many new features but they are not compelling enough to convince me to switch from Office 2003. Finally as an incentive to attending the conference each of us received an Office 2007 copy and a T-shirt. Microsoft has put up a new website (DinnerNow.net) that leverages several new Microsoft technologies like IIS7, ASP.NET Ajax Extensions, Linq, Windows Communication Foundation, Windows Workflow Foundation, Windows Presentation Foundation, Windows Powershell, and the .NET Compact Framework. You can also download the whole source code for the site starting Jan 31st, 2007 to look at how all these technologies work together.