<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-35631598</id><updated>2011-12-18T22:52:41.914-08:00</updated><category term='C#'/><category term='JQuery'/><category term='Motivation'/><category term='debugging'/><category term='Sessions'/><category term='GridView'/><category term='AJAX'/><category term='asp.net'/><category term='SqlServer'/><category term='performance'/><category term='Windows Service'/><category term='JavaScript'/><category term='Scheduler'/><category term='validation'/><title type='text'>Kode's thoughts</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>31</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-35631598.post-2822303146703805408</id><published>2009-06-07T13:37:00.001-07:00</published><updated>2009-06-09T13:03:43.606-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows Service'/><category scheme='http://www.blogger.com/atom/ns#' term='Scheduler'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Creating a Windows Task Scheduler Service</title><content type='html'>&lt;p&gt;Recently, one of my friends asked me for help in creating a windows service for scheduling some tasks. He said that he could not use the task scheduler that comes with Windows as the Task Scheduler expects each task to be a stand alone executable file. All his tasks were in a single class library and it would be a lot of work to separate each task into its own executable. Also he said that that the schedule for the tasks could change from time to time and it would be nice if he could configure the tasks in an XML file.&lt;/p&gt;  &lt;p&gt;To Recap, the requirements for the windows service are&lt;/p&gt;  &lt;p&gt;1) The tasks should be loaded from a class library&lt;/p&gt;  &lt;p&gt;2) The schedule information for the tasks should be configurable in an XML file.&lt;/p&gt;  &lt;p&gt;We googled (binged :)) for the solution and found an excellent article by Ajit Kumar &lt;a href="http://www.c-sharpcorner.com/UploadFile/ajifocus/AppScheduler05262006074807AM/AppScheduler.aspx" target="_blank"&gt;Application Scheduler Service Using C#.Net And XML&lt;/a&gt; to base our solution upon. We took some good points like configuring the task information from the above mentioned article.&lt;/p&gt;  &lt;p&gt;This is how we took a stab at our solution. We used a bit of reflection to get instances of tasks that need to run.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Configure the scheduled tasks in an XML file (Tasks.xml) &lt;/li&gt;    &lt;li&gt;On Service Start, load the the tasks configuration from the Tasks.xml file into a DataSet. &lt;/li&gt;    &lt;li&gt;Get a reference to the assembly that contains the tasks. &lt;/li&gt;    &lt;li&gt;Use a Systems.Timer to run a method (RunTaks) periodically that checks the tasks that need to run and run the tasks. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;  &lt;br /&gt;&lt;span style="font-weight: bold;"&gt;This is how the Tasks.xml file looks like&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;name is the class name of the task to run, time is date and time (MM/dd/yyyy HH:mm format) when the task should run, and repeat is how often the task should run (H- hourly, W-Weekly, M-Monthly, D-Daily)   &lt;br /&gt;&lt;/p&gt;  &lt;pre class="xml:nocontrols" name="code"&gt;&amp;lt;appSchedule&amp;gt;&lt;br /&gt;&amp;lt;task name="Task1" time="06/07/2009 12:00" repeat="H" /&amp;gt;&lt;br /&gt;&amp;lt;task name="Task2" time="06/15/2009 12:00" repeat="W" /&amp;gt;&lt;br /&gt;&amp;lt;task name="Task3" time="06/29/2009 12:00" repeat="D" /&amp;gt;&lt;br /&gt;&amp;lt;task name="Task5" time="06/10/2009 19:00" repeat="M" /&amp;gt;&lt;br /&gt;&amp;lt;/appSchedule&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;The path to the tasks.xml should be configured in the service's app.config file&lt;br /&gt;&lt;pre class="xml:nocontrols" name="code"&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt; &amp;lt;appSettings&amp;gt;&lt;br /&gt;  &amp;lt;add key=&amp;quot;tasksConfigPath&amp;quot; value=&amp;quot;E:\Training\Demo\SchedulerService\SchedulerService\Tasks.xml&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/appSettings&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Next, to ease the process of running a task, we made sure that all the tasks implement an interface ITask which has one method called RunTask that returns nothing (void).&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_dqwBsHcwTgw/SiwqcuypDRI/AAAAAAAADl4/Jm9ZyGtDLz0/s1600-h/MailTasks%5B7%5D.jpg"&gt;&lt;img style="border-width: 0px;" alt="MailTasks" src="http://lh5.ggpht.com/_dqwBsHcwTgw/SiwqdPXcoiI/AAAAAAAADl8/ltIgzvwUCew/MailTasks_thumb%5B5%5D.jpg?imgmax=800" align="left" border="0" width="236" height="195" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharp:nocontrols" name="code"&gt;namespace MailTasks&lt;br /&gt;{&lt;br /&gt;  public interface ITask&lt;br /&gt;  {&lt;br /&gt;      void RunTask();&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We used ThreadPooling to ease the burden of managing the threads. Since each task has to run in its own thread and we dont know how many threads to create, we zeroed in on ThreadPooling to manage the threads.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have System.Timer object that periodically calls the RunTasks method. We use the global boolean variable workInProgress to track if the RunTasks method is running or idling. If the workInProgress is true we just return to wait for the completion of the earlier call to RunTasks method. If the workInProgress is false, we proceed further to run the scheduled tasks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We get the list of tasks to run by calling a method &lt;strong&gt;&lt;em&gt;GetTasksToRun(). &lt;/em&gt;&lt;/strong&gt;Inside the GetTasksToRun method, we go through the DataSet with the tasks schedule information, for each task scheduled, if the current time is greater than the scheduled time, using reflection we create the Task Object that needs to run and then add it to the list of tasks to run.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once we get the list of tasks to run, we update a global variable numBusy with the count of tasks to run. This numBusy variable will be used to track the number of busy threads at any given time. we loop through the scheduled tasks list, and queue each task in the ThreadPool by passing reference to a method (DoTask) and the task object itself to the ThreadPool's QueueUserWorkItem method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Inside the &lt;strong&gt;DoTask&lt;/strong&gt; method, we call the RunTask() method on the task object passed in as an argument. We update the next run time for the task in the DataSet by calling the method &lt;strong&gt;UpdateNextRunTime &lt;/strong&gt;&lt;em&gt;&lt;/em&gt;and decrement the count of busy threads (numBusy) in the finally.&lt;br /&gt;&lt;br /&gt;Back in the RunTasks method we wait for all the threads to complete by calling WaitOne() method on the ManualResetEvent object &lt;strong&gt;doneEvent&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After all the queued tasks are complete, we persist the tasks data in the DataSet back to the disk and set workInProgress to false to mark the completion of all the tasks queued.&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharp:nocontrols" name="code"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Diagnostics;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Reflection;&lt;br /&gt;using System.ServiceProcess;&lt;br /&gt;using System.Threading;&lt;br /&gt;using System.Timers;&lt;br /&gt;using System.Xml;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using MailTasks;&lt;br /&gt;namespace SchedulerService&lt;br /&gt;{&lt;br /&gt;    public partial class Scheduler : ServiceBase&lt;br /&gt;    {&lt;br /&gt;        private static ManualResetEvent doneEvent;&lt;br /&gt;        private static string configPath = string.Empty;&lt;br /&gt;        private static int numBusy;&lt;br /&gt;        private static DataSet dsTasks;&lt;br /&gt;        private const string TASKS_NAME_SPACE = "MailTasks."; //Period is needed&lt;br /&gt;        private const string DATE_FORMAT_STRING = "MM/dd/yyyy HH:mm";&lt;br /&gt;        private static Assembly tasksAssembly;&lt;br /&gt;        private static EventLog eventLog1;&lt;br /&gt;        readonly System.Timers.Timer _timer = new System.Timers.Timer();&lt;br /&gt;        private static bool workInProgress;&lt;br /&gt;&lt;br /&gt;        public Scheduler()&lt;br /&gt;        {&lt;br /&gt;            InitializeComponent();&lt;br /&gt;            if (!EventLog.SourceExists("MailScheduler"))&lt;br /&gt;                EventLog.CreateEventSource("MailScheduler", "Application" );&lt;br /&gt;&lt;br /&gt;            eventLog1 = new EventLog("Application", Environment.MachineName, "MailScheduler");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected override void OnStart(string[] args)&lt;br /&gt;        {&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Mail Scheduler Service Started");&lt;br /&gt;                LoadTasksIntoDataSet();&lt;br /&gt;                LoadTasksAssembly();&lt;br /&gt;                _timer.Interval = 60000;&lt;br /&gt;                _timer.Elapsed += RunTasks;&lt;br /&gt;                _timer.Start();&lt;br /&gt;            }&lt;br /&gt;            catch (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Error occurred OnStart "+ex.Message);  &lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected override void OnStop()&lt;br /&gt;        {&lt;br /&gt;            eventLog1.WriteEntry("MailScheduler service stopped");&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                UpdateTasksConfigonDisk();&lt;br /&gt;            }&lt;br /&gt;            catch(Exception ex)&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Error occurred onStop "+ex.Message);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static void RunTasks(object sender, ElapsedEventArgs args)&lt;br /&gt;        {&lt;br /&gt;            //If the processing of RunTasks lasts longer than the Timer's interval, RunTasks could be called&lt;br /&gt;            //again before the previous call finished. To overcome this, using a bool variable workInProgress to track if this method is in progress&lt;br /&gt;            //If not, go ahead else return &lt;br /&gt;            if (workInProgress) return;&lt;br /&gt;&lt;br /&gt;            numBusy = 0;&lt;br /&gt;           // LoadTasksIntoDataSet();&lt;br /&gt;            doneEvent = new ManualResetEvent(false);&lt;br /&gt;&lt;br /&gt;            List&lt;ITask&gt; tasksList = GetTasksToRun();&lt;br /&gt;            numBusy = tasksList.Count; //Number of threads to create is not constant, depends on the tasks ready to run at a given time&lt;br /&gt;            if (numBusy &gt; 0)&lt;br /&gt;            {&lt;br /&gt;                workInProgress = true;&lt;br /&gt;                foreach (ITask task in tasksList)&lt;br /&gt;                {&lt;br /&gt;                    ThreadPool.QueueUserWorkItem(DoTask, task);&lt;br /&gt;                }&lt;br /&gt;                doneEvent.WaitOne();&lt;br /&gt;            }&lt;br /&gt;            //All scheduled tasks completed, persist the tasks data to disk,iteration over&lt;br /&gt;            if (numBusy == 0 &amp;&amp; tasksList.Count &gt; 0)&lt;br /&gt;            {&lt;br /&gt;                workInProgress = false;&lt;br /&gt;                UpdateTasksConfigonDisk();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static void DoTask(object o)&lt;br /&gt;        {&lt;br /&gt;            ITask task = o as ITask;&lt;br /&gt;            if (task == null) return;&lt;br /&gt;            string scheduleName = task.GetType().ToString();&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                //Event Log, starting task at this time.&lt;br /&gt;                task.RunTask();&lt;br /&gt;                //Task completed successfuly at this time&lt;br /&gt;               &lt;br /&gt;                int lastIndexOfPeriod = scheduleName.LastIndexOf(".");&lt;br /&gt;                UpdateNextRunTime(scheduleName.Substring(lastIndexOfPeriod + 1));&lt;br /&gt;            }&lt;br /&gt;            catch (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Error occurred while executing task: " + scheduleName);&lt;br /&gt;                eventLog1.WriteEntry("Stack Trace is: " + ex.Message);&lt;br /&gt;            }&lt;br /&gt;            finally&lt;br /&gt;            {&lt;br /&gt;                if (Interlocked.Decrement(ref numBusy) == 0)&lt;br /&gt;                {&lt;br /&gt;                    doneEvent.Set();&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static void LoadTasksIntoDataSet()&lt;br /&gt;        {&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Trying to Load Tasks into DataSet"); &lt;br /&gt;                configPath = ConfigurationManager.AppSettings["tasksConfigPath"];&lt;br /&gt;                XmlTextReader xmlTextReader = new XmlTextReader(configPath);&lt;br /&gt;                XmlDataDocument xdoc1 = new XmlDataDocument();&lt;br /&gt;                xdoc1.DataSet.ReadXml(xmlTextReader, XmlReadMode.InferSchema);&lt;br /&gt;                dsTasks = xdoc1.DataSet;&lt;br /&gt;                xmlTextReader.Close();&lt;br /&gt;                eventLog1.WriteEntry("Finished Loading Tasks into DataSet");&lt;br /&gt;            }&lt;br /&gt;            catch(Exception ex)&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Error occurred while loading tasks into DataSet " + ex.Message);&lt;br /&gt;                throw;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static void UpdateTasksConfigonDisk()&lt;br /&gt;        {&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Attempting to save tasks information to disk ");  &lt;br /&gt;                StreamWriter sWrite = new StreamWriter(configPath);&lt;br /&gt;                XmlTextWriter xWrite = new XmlTextWriter(sWrite);&lt;br /&gt;                dsTasks.WriteXml(xWrite, XmlWriteMode.WriteSchema);&lt;br /&gt;                xWrite.Close();&lt;br /&gt;            }&lt;br /&gt;            catch (Exception ex)&lt;br /&gt;            {&lt;br /&gt;               eventLog1.WriteEntry("Error occurred while savings tasks information to disk "+ex.Message);  &lt;br /&gt;               throw;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        //updating the dataset is not thread safe&lt;br /&gt;        private static void UpdateNextRunTime(string taskName)&lt;br /&gt;        {&lt;br /&gt;            if (dsTasks == null) return;&lt;br /&gt;            foreach (DataRow row in dsTasks.Tables[0].Rows)&lt;br /&gt;            {&lt;br /&gt;                if (taskName.ToLower() != row[0].ToString().ToLower()) continue;&lt;br /&gt;                DateTime scheduledTime = DateTime.Parse(row[1].ToString());&lt;br /&gt;                string repeat = row["repeat"].ToString().ToUpper();&lt;br /&gt;                switch (repeat)&lt;br /&gt;                {&lt;br /&gt;                    case "H":&lt;br /&gt;                        scheduledTime = scheduledTime.AddHours(1);&lt;br /&gt;                        if (scheduledTime &lt; DateTime.Now)&lt;br /&gt;                            scheduledTime = DateTime.Now.AddHours(1);&lt;br /&gt;                        break;&lt;br /&gt;                    case "D":&lt;br /&gt;                        while (scheduledTime &lt; DateTime.Now)&lt;br /&gt;                        {&lt;br /&gt;                            scheduledTime = scheduledTime.AddDays(1);&lt;br /&gt;                        }&lt;br /&gt;                        break;&lt;br /&gt;                    case "W":&lt;br /&gt;                        while (scheduledTime &lt; DateTime.Now)&lt;br /&gt;                        {&lt;br /&gt;                            scheduledTime = scheduledTime.AddDays(7);&lt;br /&gt;                        }&lt;br /&gt;                        break;&lt;br /&gt;                    case "M":&lt;br /&gt;                        while (scheduledTime &lt; DateTime.Now)&lt;br /&gt;                        {&lt;br /&gt;                            scheduledTime = scheduledTime.AddMonths(1);&lt;br /&gt;                        }&lt;br /&gt;                        break;&lt;br /&gt;                }&lt;br /&gt;                row[1] = scheduledTime.ToString(DATE_FORMAT_STRING);&lt;br /&gt;                dsTasks.AcceptChanges();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static List&lt;ITask&gt; GetTasksToRun()&lt;br /&gt;        {&lt;br /&gt;            if (dsTasks == null) return null;&lt;br /&gt;            List&lt;ITask&gt; tasks = new List&lt;ITask&gt;();&lt;br /&gt;            foreach (DataRow row in dsTasks.Tables[0].Rows)&lt;br /&gt;            {&lt;br /&gt;                DateTime scheduledTime = DateTime.Parse(row[1].ToString());&lt;br /&gt;                if (DateTime.Now &lt; scheduledTime) continue;&lt;br /&gt;                ITask task = CreateTaskInstance(row[0].ToString());&lt;br /&gt;                if (task != null)&lt;br /&gt;                    tasks.Add(task);&lt;br /&gt;            }&lt;br /&gt;            return tasks;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static ITask CreateTaskInstance(string taskName)&lt;br /&gt;        {&lt;br /&gt;            string taskFullName = TASKS_NAME_SPACE + taskName;&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                if(tasksAssembly==null)&lt;br /&gt;                    throw new Exception("Tasks Assembly is null, cannot proceed further..");&lt;br /&gt;                //Create an instance of the task&lt;br /&gt;                ITask task = (ITask)tasksAssembly.CreateInstance(taskFullName, true);&lt;br /&gt;                return task;&lt;br /&gt;            }&lt;br /&gt;            catch (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Error occurred while creating Task Instance " + ex.Message);  &lt;br /&gt;            }&lt;br /&gt;            return null;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static void LoadTasksAssembly()&lt;br /&gt;        {&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                if (tasksAssembly == null)&lt;br /&gt;                    tasksAssembly = Assembly.GetAssembly(typeof(MailTasks.ITask));&lt;br /&gt;            }&lt;br /&gt;            catch(Exception ex)&lt;br /&gt;            {&lt;br /&gt;                eventLog1.WriteEntry("Error occurred while loading tasks Assembly " + ex.Message);&lt;br /&gt;                throw;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-2822303146703805408?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/2822303146703805408/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=2822303146703805408' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/2822303146703805408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/2822303146703805408'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/06/creating-windows-task-scheduler-service.html' title='Creating a Windows Task Scheduler Service'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_dqwBsHcwTgw/SiwqdPXcoiI/AAAAAAAADl8/ltIgzvwUCew/s72-c/MailTasks_thumb%5B5%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-5580770632521038537</id><published>2009-05-22T11:37:00.000-07:00</published><updated>2009-05-25T07:30:45.334-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='validation'/><title type='text'>Limit the characters in a multi row textbox</title><content type='html'>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.&lt;br /&gt;&lt;pre name="code" class="js:nocontrols"&gt;&lt;br /&gt;function ValidateCharCount(txtBox, maxLength,controlName) {&lt;br /&gt;    var input;&lt;br /&gt;    var length;&lt;br /&gt;&lt;br /&gt;    input = txtBox.value;&lt;br /&gt;    length = input.length;&lt;br /&gt;    &lt;br /&gt;    var allowedLength = new Number(maxLength);&lt;br /&gt;    if (length &gt; allowedLength) {&lt;br /&gt;        txtBox.value = txtBox.value.substring(0, allowedLength);&lt;br /&gt;        alert(" Only " + maxLength + " characters are allowed in the field " + controlName);&lt;br /&gt;        txtBox.focus(); &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;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 allowed length.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Usage:&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="xml:nocontrols"&gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;text&amp;quot; rows=&amp;quot;5&amp;quot; id=&amp;quot;Description&amp;quot; onfocusout=&amp;quot;ValidateCharCount(this,100,'Description')&amp;quot; /&amp;gt;  &lt;br /&gt;&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-5580770632521038537?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/5580770632521038537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=5580770632521038537' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/5580770632521038537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/5580770632521038537'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/05/limit-characters-in-multi-row-textbox.html' title='Limit the characters in a multi row textbox'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-8336904081825552432</id><published>2009-05-22T11:29:00.000-07:00</published><updated>2009-05-25T07:31:02.017-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Motivation'/><title type='text'>IF by Rudyard Kipling</title><content type='html'>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.&lt;br /&gt;Here it is in its entirety.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;[IF] &lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;If you can keep your head when all about you&lt;br /&gt;Are losing theirs and blaming it on you,&lt;br /&gt;If you can trust yourself when all men doubt you&lt;br /&gt;But make allowance for their doubting too,&lt;br /&gt;If you can wait and not be tired by waiting,&lt;br /&gt;Or being lied about, don't deal in lies,&lt;br /&gt;Or being hated, don't give way to hating,&lt;br /&gt;And yet don't look too good, nor talk too wise:&lt;br /&gt;&lt;br /&gt;If you can dream--and not make dreams your master,&lt;br /&gt;If you can think--and not make thoughts your aim;&lt;br /&gt;If you can meet with Triumph and Disaster&lt;br /&gt;And treat those two impostors just the same;&lt;br /&gt;If you can bear to hear the truth you've spoken&lt;br /&gt;Twisted by knaves to make a trap for fools,&lt;br /&gt;Or watch the things you gave your life to, broken,&lt;br /&gt;And stoop and build 'em up with worn-out tools:&lt;br /&gt;&lt;br /&gt;If you can make one heap of all your winnings&lt;br /&gt;And risk it all on one turn of pitch-and-toss,&lt;br /&gt;And lose, and start again at your beginnings&lt;br /&gt;And never breath a word about your loss;&lt;br /&gt;If you can force your heart and nerve and sinew&lt;br /&gt;To serve your turn long after they are gone,&lt;br /&gt;And so hold on when there is nothing in you&lt;br /&gt;Except the Will which says to them: "Hold on!"&lt;br /&gt;&lt;br /&gt;If you can talk with crowds and keep your virtue,&lt;br /&gt;Or walk with kings--nor lose the common touch,&lt;br /&gt;If neither foes nor loving friends can hurt you;&lt;br /&gt;If all men count with you, but none too much,&lt;br /&gt;If you can fill the unforgiving minute&lt;br /&gt;With sixty seconds' worth of distance run,&lt;br /&gt;Yours is the Earth and everything that's in it,&lt;br /&gt;And--which is more--you'll be a Man, my son!&lt;/blockquote&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;--Rudyard Kipling &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-8336904081825552432?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/8336904081825552432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=8336904081825552432' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8336904081825552432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8336904081825552432'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/05/if-by-rudyard-kipling.html' title='IF by Rudyard Kipling'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-6676316238858666963</id><published>2009-05-11T10:00:00.000-07:00</published><updated>2009-05-25T07:31:18.829-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='debugging'/><title type='text'>Debug classic ASP in Visual Studio 2008 with SP1</title><content type='html'>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.&lt;br /&gt;1) &lt;span style="font-weight: bold;"&gt;Enable ASP server side script debugging in IIS&lt;/span&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dqwBsHcwTgw/SghaNstNSwI/AAAAAAAADik/kaIfeawNw3g/s1600-h/IIs.jpg"&gt;&lt;img src="http://2.bp.blogspot.com/_dqwBsHcwTgw/SghaNstNSwI/AAAAAAAADik/kaIfeawNw3g/s320/IIs.jpg" alt="" id="BLOGGER_PHOTO_ID_5334612950005926658" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;b. In the application configuration window, select the debugging tab and make sure that enable &lt;span style="font-weight: bold;"&gt;ASP server-side script debugging is checked&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dqwBsHcwTgw/SghaZHRWd8I/AAAAAAAADis/pEqZi40fC9U/s1600-h/enable.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; " src="http://1.bp.blogspot.com/_dqwBsHcwTgw/SghaZHRWd8I/AAAAAAAADis/pEqZi40fC9U/s320/enable.jpg" alt="" id="BLOGGER_PHOTO_ID_5334613146115405762" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;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&lt;br /&gt;3) Once the application is launched, go to Debug --&gt; &lt;span style="font-weight: bold;"&gt;Attach to Process&lt;/span&gt; to launch the Attach to process window. In that window, click on the &lt;span style="font-weight: bold;"&gt;Show Processes for all users&lt;/span&gt; checkbox to show all processes.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dqwBsHcwTgw/SghajvCYD1I/AAAAAAAADi0/P6qCOPGhWtQ/s1600-h/Attach.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 574px; height: 286px;" src="http://1.bp.blogspot.com/_dqwBsHcwTgw/SghajvCYD1I/AAAAAAAADi0/P6qCOPGhWtQ/s320/Attach.jpg" alt="" id="BLOGGER_PHOTO_ID_5334613328588705618" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4) In the list of available processes, select the process dllhost.exe with user name &lt;span style="font-weight: bold;"&gt;COMPUTERName\IWAM_COMPUTERNAME&lt;/span&gt; and click Attach.&lt;br /&gt;5) Set a break point in classic ASP code you want to browse, the execution should stop at the break point&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-6676316238858666963?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/6676316238858666963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=6676316238858666963' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/6676316238858666963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/6676316238858666963'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/05/debug-classic-asp-in-visual-studio-2008.html' title='Debug classic ASP in Visual Studio 2008 with SP1'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_dqwBsHcwTgw/SghaNstNSwI/AAAAAAAADik/kaIfeawNw3g/s72-c/IIs.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-8033508247666760248</id><published>2009-05-09T13:05:00.000-07:00</published><updated>2009-06-06T09:05:46.799-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='GridView'/><category scheme='http://www.blogger.com/atom/ns#' term='validation'/><title type='text'>Adding custom client side validation to controls inside GridView</title><content type='html'>Some times we find it necessary to provide custom validation to controls inside a GridView.&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To Recap&lt;br /&gt;Requirements:&lt;br /&gt;&lt;/span&gt;&lt;span&gt;Make sure that a value is selected from the country dropdownlist.&lt;br /&gt;When "Other" is selected for country, show a textbox to show enter what the "Other" country is&lt;br /&gt;Make sure that a value is entered in the textbox when "Other" is selected&lt;br /&gt;&lt;br /&gt;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&lt;br /&gt;Leaving out the databinding details.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I also add an eventhandler for OnRowDataBound event.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml:nocontrols"&gt;&lt;br /&gt;&amp;lt;asp:GridView ID="grdSales" runat="server"  OnRowDataBound="grdSales_RowDataBound"&lt;br /&gt;ShowFooter="true"&amp;gt;&lt;br /&gt;&amp;lt;Columns&amp;gt;&lt;br /&gt;&amp;lt;asp:TemplateField HeaderText="Country"&amp;gt;&lt;br /&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;asp:RequiredFieldValidator runat="server" ID="reqValCountry" ControlToValidate="ddlCountry"&lt;br /&gt; Display="Dynamic" ErrorMessage="Country is required&amp;lt;br&amp;gt;" ValidationGroup="Country"&amp;gt;&amp;lt;/asp:RequiredFieldValidator&amp;gt;&lt;br /&gt;&amp;lt;asp:DropDownList ID="ddlCountry" runat="server"&amp;gt;&lt;br /&gt; &amp;lt;asp:ListItem Value=""&amp;gt; --Select Country--&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt; &amp;lt;asp:ListItem Value="1"&amp;gt;USA&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt; &amp;lt;asp:ListItem Value="2"&amp;gt;Canada&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt; &amp;lt;asp:ListItem Value="3"&amp;gt;Mexico&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt; &amp;lt;asp:ListItem Value="4"&amp;gt;Other&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;br /&gt;&amp;lt;asp:Panel ID="pnlOther" Style="display: none" runat="server"&amp;gt;&lt;br /&gt; Other:&amp;amp;nbsp;&amp;lt;asp:TextBox runat="server" ID="txtOther"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt; &amp;lt;asp:CustomValidator ID="custValCountry" runat="server" ValidationGroup="Country"&lt;br /&gt;  ControlToValidate="ddlCountry" ClientValidationFunction="ValidateCountry"&lt;br /&gt;  ErrorMessage="Other is required"&amp;gt;&amp;lt;/asp:CustomValidator&amp;gt;&lt;br /&gt;&amp;lt;/asp:Panel&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;&amp;lt;/Columns&amp;gt;&lt;br /&gt;&amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To meet the first requirement add a required field validator to ddlCountry drowdownlist.&lt;br /&gt;For the second requirement, I need to add an onchange Event to the dropdownlist. In the event handler, I want to inspect the value selected and show the panel that contains the text box.&lt;br /&gt;For the third requirement, I added a custom validator which calls a javascript function ValidateCountry.&lt;br /&gt;&lt;br /&gt;Inside the grdCountry_RowDataBound event handler, pass the appropriate ids of the controls to the javascript functions.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="c#:nocontrols"&gt;&lt;br /&gt;protected void grdSales_RowDataBound(object sender, GridViewRowEventArgs e)&lt;br /&gt;{&lt;br /&gt;if (e.Row.RowType != DataControlRowType.DataRow) return;&lt;br /&gt;&lt;br /&gt;DropDownList ddl = e.Row.FindControl("ddlCountry") as DropDownList;&lt;br /&gt;Panel pnl = e.Row.FindControl("pnlOther") as Panel;&lt;br /&gt;TextBox txt = e.Row.FindControl("txtOther") as TextBox;&lt;br /&gt;CustomValidator val = e.Row.FindControl("custValCountry") as CustomValidator;&lt;br /&gt;&lt;br /&gt;if (ddl == null || pnl == null || txt == null || val == null) return;&lt;br /&gt;&lt;br /&gt;//Add an onchange event to the ddlCountry drop down list which is in each data row of the grid view&lt;br /&gt;//The javascript function will take as parameters Ids of the drop down list and the div that should be shows/hid&lt;br /&gt;&lt;br /&gt;string jsToggle = "TogleCountry('" + ddl.ClientID + "','" + pnl.ClientID + "')";&lt;br /&gt;ddl.Attributes.Add("onchange", jsToggle);&lt;br /&gt;&lt;br /&gt;//The custom validation control will validate the drop down list. If option Other is selcted, it checks&lt;br /&gt;//if the txtOther has some text&lt;br /&gt;//Here we are adding ids of the ddlCountry and txtOther as client attributes of the validation control&lt;br /&gt;//These attributes can be accessed from the client side function to help in doing the custom validation&lt;br /&gt;val.Attributes.Add("ddl", ddl.ClientID);&lt;br /&gt;val.Attributes.Add("txt", txt.ClientID);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Finally the javascript functions&lt;br /&gt;I'm using ASP.net AJAX client side library here. If you are not using ASP.net AJAX just replace $get with document.getElementById&lt;br /&gt;&lt;pre name="code" class="js:nocontrols"&gt;&lt;br /&gt;function TogleCountry(ddl, div) {&lt;br /&gt;    var selectedIndex = $get(ddl).selectedIndex;&lt;br /&gt;    $get(div).style.display = 'none';&lt;br /&gt;    if (selectedIndex == 5)&lt;br /&gt;        $get(div).style.display = 'block';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function ValidateCountry(sender, args) {&lt;br /&gt;    var ddl = sender.attributes["ddl"].value; //These attributes are added to the validator in the rowdatabound event of the GridView&lt;br /&gt;    var txt = sender.attributes["txt"].value;&lt;br /&gt;&lt;br /&gt;    var selectedIndex = $get(ddl).selectedIndex;&lt;br /&gt;    var txtOther = $get(txt).value;&lt;br /&gt;&lt;br /&gt;    if (selectedIndex == 4 &amp;amp;&amp;amp; txtOther.length &lt; isvalid =" false;" isvalid =" true;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-8033508247666760248?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/8033508247666760248/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=8033508247666760248' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8033508247666760248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8033508247666760248'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/05/adding-custom-client-side-validation-to.html' title='Adding custom client side validation to controls inside GridView'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-8849733337624967368</id><published>2009-05-09T12:25:00.000-07:00</published><updated>2009-05-25T07:32:06.849-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='performance'/><category scheme='http://www.blogger.com/atom/ns#' term='SqlServer'/><title type='text'>Find the cause of poor performance in Sql Server</title><content type='html'>I found the following two part article by Gail Shaw on Simple-Talk really helpful in trouble shooting poorly performing queries in Sql Server.&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;Part 1: &lt;a href="http://tinyurl.com/ccl6gj"&gt;http://tinyurl.com/ccl6gj&lt;/a&gt;&lt;br /&gt;Part 2:&lt;a href="http://tinyurl.com/okcuqg"&gt;http://tinyurl.com/okcuqg&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-8849733337624967368?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/8849733337624967368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=8849733337624967368' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8849733337624967368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8849733337624967368'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/05/find-cause-of-poor-performance-in-sql.html' title='Find the cause of poor performance in Sql Server'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-1429857245902049068</id><published>2009-05-09T11:56:00.000-07:00</published><updated>2009-05-25T07:32:22.318-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JQuery'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='validation'/><title type='text'>Validating checkbox list in asp.net using JQuery</title><content type='html'>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.&lt;br /&gt;&lt;br /&gt;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. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml:nocontrols"&gt;&lt;br /&gt;   &amp;lt;asp:CheckBoxList ID=&amp;quot;cblLostDescription&amp;quot; runat=&amp;quot;server&amp;quot; RepeatDirection=&amp;quot;Horizontal&amp;quot; TabIndex=&amp;quot;14&amp;quot;&amp;gt;&lt;br /&gt;           &amp;lt;asp:ListItem Value=&amp;quot;L&amp;quot;&amp;gt;Lost/Stolen&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;          &amp;lt;asp:ListItem Value=&amp;quot;D&amp;quot;&amp;gt;Destroyed&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;          &amp;lt;asp:ListItem Value=&amp;quot;M&amp;quot;&amp;gt;Damaged&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;          &amp;lt;asp:ListItem Value=&amp;quot;O&amp;quot;&amp;gt;Other&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;&amp;lt;/asp:CheckBoxList&amp;gt;&lt;br /&gt;&amp;lt;asp:CustomValidator ID=&amp;quot;custValDescrption&amp;quot; runat=&amp;quot;server&amp;quot;  ErrorMessage=&amp;quot;Property Description is required&amp;quot;&lt;br /&gt;Display=&amp;quot;Dynamic&amp;quot; ControlToValidate=&amp;quot;txtPropertyDummy&amp;quot;&lt;br /&gt;ClientValidationFunction=&amp;quot;ValidatePropertyDescription&amp;quot; ValidateEmptyText=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;/asp:CustomValidator&amp;gt;&lt;br /&gt;&amp;lt;asp:TextBox runat=&amp;quot;server&amp;quot; ID=&amp;quot;txtPropertyDummy&amp;quot; Width=&amp;quot;1px&amp;quot; Style=&amp;quot;display: none&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Following is the client side validation function that we added to the custom validator. If we take a look at the rendered html, all The checkboxes in our list do not have the same id or name attribute.But all the ids start with the id we gave to the checkbox list. We can use JQeury to select the group of checkboxes whose ids start with a given text , then loop through the set and verify if at least one checkbox is checked.&lt;span style="font-weight:bold;"&gt; Make sure you have a reference to the JQuery script file on your asp.net page.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="js:nocontrols"&gt;&lt;br /&gt;   //Using JQuery, select all the checkboxes whose id begins with the &lt;br /&gt;   //asp.net checkbox list server control's ID.&lt;br /&gt;   function ValidatePropertyDescription(sender, args) {&lt;br /&gt;        var chkGroup = $("input[id^=&lt;%=cblLostDescription.ClientID%&gt;]"); &lt;br /&gt;        //Loop through the set returned by JQuery&lt;br /&gt;        for (i = 0; i &lt; chkGroup.length; i++) {&lt;br /&gt;            if (chkGroup[i].checked) {&lt;br /&gt;                args.IsValid = true;&lt;br /&gt;                return;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        args.IsValid = false;&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-1429857245902049068?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/1429857245902049068/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=1429857245902049068' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/1429857245902049068'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/1429857245902049068'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/05/validating-checkbox-list-in-aspnet.html' title='Validating checkbox list in asp.net using JQuery'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-4238481377137262410</id><published>2009-04-26T14:04:00.000-07:00</published><updated>2009-05-25T07:32:41.718-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='validation'/><title type='text'>Clear Validation Errors and Validation Summary messages</title><content type='html'>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.&lt;br /&gt;&lt;br /&gt;The following javascript code snippet can be used to clear the validation error messages.&lt;br /&gt;Have a reset button on your form and call the following js function onclick.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;&amp;lt;input type="reset" onclick="HideValidationErrors();" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;     function HideValidators() {&lt;br /&gt;        //Hide all validation errors&lt;br /&gt;        if (window.Page_Validators)&lt;br /&gt;            for (var vI = 0; vI &lt; Page_Validators.length; vI++) {&lt;br /&gt;            var vValidator = Page_Validators[vI];&lt;br /&gt;            vValidator.isvalid = true;&lt;br /&gt;            ValidatorUpdateDisplay(vValidator);&lt;br /&gt;        }&lt;br /&gt;        //Hide all validaiton summaries&lt;br /&gt;        if (typeof (Page_ValidationSummaries) != "undefined") { //hide the validation summaries&lt;br /&gt;            for (sums = 0; sums &lt; Page_ValidationSummaries.length; sums++) {&lt;br /&gt;                summary = Page_ValidationSummaries[sums];&lt;br /&gt;                summary.style.display = "none";&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-4238481377137262410?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/4238481377137262410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=4238481377137262410' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/4238481377137262410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/4238481377137262410'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2009/04/reset-validation-errors-and-validation.html' title='Clear Validation Errors and Validation Summary messages'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-6449792720056536654</id><published>2008-06-11T09:42:00.000-07:00</published><updated>2008-06-14T05:01:45.951-07:00</updated><title type='text'>PostBack the form when a value is selected from the results returned by autocomplete extender</title><content type='html'>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 &lt;span style="font-weight: bold;"&gt;OnClientItemSelected &lt;/span&gt;which takes a javascript method name as value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;&amp;lt;asp:UpdatePanel runat="server" id="UpdatePanel1" &amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;    &amp;lt;asp:TextBox ID="txtOrderNumber" runat="server"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        AutoCompleteType="Disabled" MaxLength="5"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        &amp;lt;ajaxToolkit:AutoCompleteExtender ID="OrderNumberAutoCompleteExtender"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        runat="server" CompletionInterval="100" CompletionSetCount="20"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        EnableCaching="true" MinimumPrefixLength="2"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        ServiceMethod="GetOrderList" ServicePath="~/ASPX/Common/AutoComplete.asmx"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        TargetControlID="txtOrderNumber" &lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(51, 51, 255);"&gt;     OnClientItemSelected="OrderNumberChanged" &lt;/span&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;&amp;lt;/asp:UpdatePanel&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;&amp;lt;Script type="text/javascript"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;          function OrderNumberChanged( source, eventArgs )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;                __doPostBack('&amp;lt;%=UpdatePanel1.ClientID%&amp;gt;', ''); //do a postback&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 51, 255);"&gt;&amp;lt;/Script&amp;gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-6449792720056536654?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/6449792720056536654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=6449792720056536654' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/6449792720056536654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/6449792720056536654'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2008/06/postback-form-when-value-is-selected.html' title='PostBack the form when a value is selected from the results returned by autocomplete extender'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-131995996411613481</id><published>2008-06-11T09:38:00.000-07:00</published><updated>2009-05-25T07:32:58.879-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><title type='text'>AutoComplete Extender dropping leading zeroes from the values in the result set</title><content type='html'>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.&lt;br /&gt;&lt;br /&gt;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&lt;br /&gt;&lt;br /&gt;In your web method or page method  do the following.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;resultList.Add("'"+result+"'"); //Single quotes are need as a work around for a known bug in autocomplete extender. Leading zeroes are dropped without quotes.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-131995996411613481?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/131995996411613481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=131995996411613481' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/131995996411613481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/131995996411613481'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2008/06/autocomplete-extender-dropping-leading.html' title='AutoComplete Extender dropping leading zeroes from the values in the result set'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-6706232701466127929</id><published>2008-06-02T12:18:00.000-07:00</published><updated>2010-10-01T11:24:48.835-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><title type='text'>Check if a Child Window is closed  using Javascript</title><content type='html'>&lt;span style="color: rgb(51, 51, 51);"&gt;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.&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(51, 0, 153);"&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;script language="javascript"&amp;gt;&lt;br /&gt;&lt;br /&gt;var detailsWindowTimer;&lt;br /&gt;var detailsWindow;&lt;br /&gt;&lt;br /&gt;function OpenDetailsWindow()&lt;br /&gt;{&lt;br /&gt;      detailsWindow = window.open('../../UserDetails.aspx?UserID=1', '    'UserDetails','directories=0,location=0,toolbar=0,status=1,menubar=0,scrollbars=1,resizable=1');                    &lt;br /&gt;     detailsWindow.focus();&lt;br /&gt;           detailsWindowTimer = setInterval("WatchDetailsWindowForClose()",2000); //Poll&lt;br /&gt;                                                       every 2 seconds to see if the details window is open or closed&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function WatchDetailsWindowForClose()&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;{&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;          if (!detailsWindow || detailsWindow.closed)&lt;br /&gt;      { &lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;                  ///  Do your stuff here....&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;                  clearInterval(detailsWindowTimer); //stop the timer&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;               &lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;}&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153); font-style: italic;font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 153);"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(102, 102, 204); font-style: italic;"&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:100%;"&gt;&amp;lt;a href="#" onclick="OpenDetailsWindow()"&amp;gt;Details&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(51, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-6706232701466127929?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/6706232701466127929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=6706232701466127929' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/6706232701466127929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/6706232701466127929'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2008/06/check-if-child-window-is-closed-using.html' title='Check if a Child Window is closed  using Javascript'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-4271033042192043359</id><published>2008-05-24T11:33:00.000-07:00</published><updated>2009-05-25T07:33:22.454-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><title type='text'>Postback the updatepanel  when an item is selected in AutoCompleteExtender</title><content type='html'>&amp;lt;asp:TextBox ID=&amp;quot;txtOrderNumber&amp;quot;  runat=&amp;quot;server&amp;quot;&lt;br /&gt;             AutoCompleteType=&amp;quot;Disabled&amp;quot; MaxLength=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;             &lt;br /&gt;         &amp;lt;ajaxToolkit:AutoCompleteExtender ID=&amp;quot;OrderNumberAutoCompleteExtender&amp;quot;&lt;br /&gt;             runat=&amp;quot;server&amp;quot; CompletionInterval=&amp;quot;100&amp;quot; CompletionSetCount=&amp;quot;20&amp;quot;&lt;br /&gt;             ContextKey=&amp;quot;region&amp;quot; EnableCaching=&amp;quot;true&amp;quot; MinimumPrefixLength=&amp;quot;2&amp;quot;&lt;br /&gt; ServiceMethod=&amp;quot;GetOrderNumberList&amp;quot; ServicePath =&amp;quot;~/ASPX/Common/AutoComplete.asmx&amp;quot;&lt;br /&gt;             TargetControlID=&amp;quot;txtOrderNumber&amp;quot; UseContextKey=&amp;quot;true&amp;quot;     OnClientItemSelected=&amp;quot;OrderNumberChanged&amp;quot; /&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-4271033042192043359?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/4271033042192043359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=4271033042192043359' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/4271033042192043359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/4271033042192043359'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2008/05/postback-updatepanel-when-item-is.html' title='Postback the updatepanel  when an item is selected in AutoCompleteExtender'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-5482505943065901364</id><published>2008-05-16T11:27:00.000-07:00</published><updated>2009-05-25T07:33:41.320-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><category scheme='http://www.blogger.com/atom/ns#' term='Sessions'/><title type='text'>How to use ASP.net  AJAX timer control to alert user when session times out.</title><content type='html'>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.&lt;br /&gt;&lt;br /&gt;Following is the approach I took. I put the code in my master page as it can be shared by all the content pages.&lt;br /&gt;&lt;br /&gt;1) Drag and drop the script manager control.&lt;br /&gt;2) Drag and drop an update panel.&lt;br /&gt;3) Set the updatepanel's &lt;span style="font-weight: bold;"&gt;UpdateMode &lt;/span&gt;property to &lt;span style="font-weight: bold;"&gt;Conditional&lt;/span&gt;.&lt;br /&gt;4) Drag and drop a Timer control inside the update panel. Set the &lt;span style="font-weight: bold;"&gt;Interval &lt;/span&gt;property to the session time out time.&lt;br /&gt;5) Set the timer control as a trigger to the update panel which causes it to postback on some event (Tick) .&lt;br /&gt;Following is the code after the first 5 steps.&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;&amp;lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;&amp;lt;/asp:ScriptManager&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;&amp;lt;asp:UpdatePanel ID="UpdatePanelMaster" UpdateMode="Conditional" runat="server"&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;    &amp;lt;ContentTemplate&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;       &amp;lt;asp:Timer ID="Timer1" runat="server" Interval="500000"&amp;gt;  &amp;lt;/asp:Timer&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;    &amp;lt;/ContentTemplate&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;    &amp;lt;Triggers&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;        &amp;lt;asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;    &amp;lt;/Triggers&amp;gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;&amp;lt;/asp:UpdatePanel&lt;/span&gt;&lt;span&gt;&lt;span style="font-style: italic; color: rgb(0, 0, 153);font-size:130%;" &gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt;6) Now we need to sprinkle some javascript to go about our business. The basic idea is we need handle  PageRequestManager's begin Request and end request events.&lt;br /&gt;&lt;br /&gt;7)In the following code, we got hold of the instance of the PageRequestManager and handled its beginRequest and endRequests event by passing our function name as the parameter.&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-style: italic;"&gt;&lt;blockquote&gt;&lt;span style="font-style: italic;"&gt;&lt;pre&gt;&lt;span style="font-style: italic;"&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   var mgr = Sys.WebForms.PageRequestManager.getInstance(); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   mgr.add_beginRequest(BeforeAjaxRequest);&lt;/span&gt;&lt;br /&gt;mgr.add_endRequest(AfterAjaxRequest);&lt;br /&gt;&lt;br /&gt;//This function is called before each AJAX request&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   function BeforeAjaxRequest(sender, args)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;      var eventTarget=$get('__EVENTTARGET').value;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;      if(eventTarget=='&amp;lt;%=Timer1.UniqueID%&amp;gt;') //if timer triggered the postback..&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;         alert('Your session has expired.');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;         window.location.href='login.aspx';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;         return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;      }&lt;/span&gt;&lt;span style="font-style: italic;"&gt;         &lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt;    //if the post back is not triggered by the timer, stop the timer&lt;br /&gt;    //so that it doesn't time out when the post back is in process.&lt;br /&gt;    var timer = $find('&lt;%= Timer1.ClientID %&gt;'); &lt;br /&gt;    if(timer!=undefined)&lt;br /&gt;    {&lt;br /&gt;       timer._stopTimer();&lt;br /&gt;    }&lt;br /&gt; }&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;  }&lt;br /&gt;&lt;br /&gt;//This event is called after each request&lt;br /&gt;function AfterAjaxRequest(sender,args)&lt;br /&gt;{&lt;br /&gt;  var timer = $find('&lt;%= Timer1.ClientID %&gt;');               &lt;br /&gt; if(timer!=undefined)&lt;br /&gt; {&lt;br /&gt;        var interval=timer.get_interval();&lt;br /&gt;        timer.set_interval(interval);&lt;br /&gt;        timer._startTimer();   //Restart the timer..&lt;br /&gt; }&lt;br /&gt;          &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;/span&gt;&lt;/span&gt;8) Every time there is a AJAX request, BeforeAJAXRequest method gets called. In that, I'm inspecting the event target to figure out who initiated the AJAX request.&lt;br /&gt;&lt;br /&gt;9) If the request is initiated by our timer control, that means the user hasn't done anything for the specified interval. If that is the case alert the user and redirect to the login page.  If it is not initiated by the timer, then stop the timer so that it doesn't time out during the postback.&lt;br /&gt;&lt;br /&gt;10)In the event handler for endRequest event, restart the timer.  Since the timer will be sitting in the master page and each content page can have their own update panels, the timer will not be reset on each postback automatically. So the timer might time out after the specified interval even though post backs happened during that interval. So to avoid that, we are stopping and starting the timer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-5482505943065901364?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/5482505943065901364/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=5482505943065901364' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/5482505943065901364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/5482505943065901364'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2008/05/aspnet-ajax-timer-control-and-session.html' title='How to use ASP.net  AJAX timer control to alert user when session times out.'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-4664756351917358150</id><published>2007-10-22T07:37:00.000-07:00</published><updated>2007-10-22T13:50:14.058-07:00</updated><title type='text'>SharePoint: Comparing dates in XSLT</title><content type='html'>&lt;p&gt;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.&lt;br /&gt;This is how I went about doing it.&lt;br /&gt;&lt;br /&gt;The trick involves converting the date string into a number&lt;br /&gt;Say the date is in &lt;strong&gt;ISO format YYYY-MM-DDTHH:MM:SSZ &lt;/strong&gt;(for example, 2001-01-21T22:54:47Z).&lt;br /&gt;&lt;br /&gt;Say we have a variable DueDate&lt;br /&gt;&lt;?xml:namespace prefix = xsl /&gt;&lt;xsl:variable name="DueDate" select="'2001-01-21T22:54:47Z'"&gt;&lt;/xsl:variable&gt;&amp;lt;xsl:variable name="DueDate" select="'2001-01-21T22:54:47Z'"&amp;gt;&lt;br /&gt;&lt;br /&gt;Replace the dashes in the string with empty string&lt;br /&gt;Take the first 10 character in the date sring&lt;br /&gt;convert the string to number&lt;br /&gt;&lt;strong&gt;number(translate(substring(@DueDate,1,10),'-',''))&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;On doing the above we get: &lt;strong&gt;20010121&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;We can do the same thing with the date to compare. We can compare the duedate with the current date in SharePoint as follows&lt;br /&gt;&lt;strong&gt;number(translate(substring(@DueDate,1,10),'-','')) &lt;span&gt;&amp; lt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;number(translate(substring(ddwrt:TodayIso(),1,10),'-',''))&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;You can apply the same logic to compare dates in different formats.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-4664756351917358150?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/4664756351917358150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=4664756351917358150' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/4664756351917358150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/4664756351917358150'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/10/sharepoint-comparing-dates-in-xslt.html' title='SharePoint: Comparing dates in XSLT'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-8614563490149471543</id><published>2007-07-11T07:08:00.000-07:00</published><updated>2007-07-11T07:13:15.027-07:00</updated><title type='text'>Gandhigiri</title><content type='html'>Some of the Indians who were affected by the USCIS revised July bulletin staged a novel protest (Gandhigiri) by sending flowers to USCIS.&lt;br /&gt;Follow the links below for more details.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ibnlive.com/news/immigrants-refused-green-cards-take-to-gandhigiri/44667-2.html?xml"&gt;http://www.ibnlive.com/news/immigrants-refused-green-cards-take-to-gandhigiri/44667-2.html?xml&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ibnlive.com/videos/44667/immigrants-refused-green-cards-take-to-gandhigiri.html"&gt;http://www.ibnlive.com/videos/44667/immigrants-refused-green-cards-take-to-gandhigiri.html&lt;br /&gt; &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-8614563490149471543?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/8614563490149471543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=8614563490149471543' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8614563490149471543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8614563490149471543'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/07/gandhigiri.html' title='Gandhigiri'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-1353203379608750691</id><published>2007-07-06T07:40:00.000-07:00</published><updated>2007-07-06T07:51:51.708-07:00</updated><title type='text'>USCIS and the 485 Fiasco....</title><content type='html'>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. &lt;br /&gt;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.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-1353203379608750691?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/1353203379608750691/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=1353203379608750691' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/1353203379608750691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/1353203379608750691'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/07/uscis-and-485-fiasco.html' title='USCIS and the 485 Fiasco....'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-8276943242647230092</id><published>2007-06-25T08:19:00.000-07:00</published><updated>2007-06-25T08:36:51.021-07:00</updated><title type='text'>Taste of Vista</title><content type='html'>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?&lt;br /&gt;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 &lt;strong&gt;IUSR&lt;/strong&gt; account permissions on the physical directory that contains the website). I thought well this is the answer and tried to launch the website from IE, and Vista threw a third line of defense which is IIS do not have permission to run ASP.Net. With the help of Google we passed the third of line of defense to successfully run our website in IIS.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-8276943242647230092?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/8276943242647230092/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=8276943242647230092' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8276943242647230092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/8276943242647230092'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/06/taste-of-vista.html' title='Taste of Vista'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-3116270975800111510</id><published>2007-03-30T12:23:00.000-07:00</published><updated>2007-03-30T12:48:12.962-07:00</updated><title type='text'>Parser Error Message: Access is denied</title><content type='html'>&lt;div&gt;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.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#ff0000;"&gt;Parser Error Message: Access is denied&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color:#ffcc33;"&gt;&lt;a href="http://2.bp.blogspot.com/_dqwBsHcwTgw/Rg1oDMKuM6I/AAAAAAAAAAo/2Bjb55jZDbM/s1600-h/capture1.jpg"&gt;&lt;strong&gt;&lt;em&gt;&lt;img id="BLOGGER_PHOTO_ID_5047805161367286690" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_dqwBsHcwTgw/Rg1oDMKuM6I/AAAAAAAAAAo/2Bjb55jZDbM/s320/capture1.jpg" border="0" /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="color:#333333;"&gt;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.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#333333;"&gt;More on the error can be found at &lt;a href="http://support.microsoft.com/kb/329065"&gt;MSDN&lt;/a&gt;.&lt;/span&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-3116270975800111510?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/3116270975800111510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=3116270975800111510' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/3116270975800111510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/3116270975800111510'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/03/parser-error-message-access-is-denied.html' title='Parser Error Message: Access is denied'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_dqwBsHcwTgw/Rg1oDMKuM6I/AAAAAAAAAAo/2Bjb55jZDbM/s72-c/capture1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-3853742833814220482</id><published>2007-03-24T13:16:00.000-07:00</published><updated>2007-03-24T13:24:43.374-07:00</updated><title type='text'>Inida face early exit from the world cup</title><content type='html'>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.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-3853742833814220482?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/3853742833814220482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=3853742833814220482' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/3853742833814220482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/3853742833814220482'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/03/inida-face-early-exit-from-world-cup.html' title='Inida face early exit from the world cup'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-7559705732573251314</id><published>2007-02-03T20:52:00.000-08:00</published><updated>2007-02-08T14:40:07.929-08:00</updated><title type='text'>Getting Started with ASP.NET AJAX</title><content type='html'>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.&lt;br /&gt;&lt;br /&gt;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 &lt;a href="http://www.asp.net/learn/videos/default.aspx?tabid=63"&gt;website &lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here I will go through the process of getting started with Microsoft ASP.NET AJAX. You can access this post here on Google docs.&lt;br /&gt;&lt;a class="tabcontent" id="publishedDocumentUrl" href="http://docs.google.com/View?docid=dd8p9vd3_7dzckx7" target="_blank"&gt;http://docs.google.com/View?docid=dd8p9vd3_7dzckx7&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Install MS AJAX&lt;/strong&gt;&lt;br /&gt;Download and install Atlas from here.(&lt;a href="http://ajax.asp.net/downloads/default.aspx?tabid=47"&gt;http://ajax.asp.net/downloads/default.aspx?tabid=47&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Visual Studio Tool Box&lt;/strong&gt;&lt;br /&gt;After installing MS AJAX, you should see AJAX Extensions tab in the visual studio tool box.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;New ASP.NET project template&lt;/strong&gt;&lt;br /&gt;A new project template that allows you to create ASP.NET AJAX enabled Web applications is also installed on installing Atlas.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Programming with Atlas&lt;/strong&gt;&lt;br /&gt;Atlas offers you two ways of building AJAX functionality into your website.&lt;br /&gt;1) Using Update Panel Control to do partial rendering&lt;br /&gt;2) Ability to place calls to remote endpoints.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Update Panel&lt;/strong&gt;&lt;br /&gt;Using Update Panel greatly simplifies AJAX programming. All you have to do is wrap the controls that need to be updated partially and asynchronously inside the update panel. The Update panel intercepts any form submissions and data being sent and routes them through XMLHttpRequest to the server. When the response is ready, the update panel updates the DOM tree by updating only the controls which are part of the update panel. The beauty of the update panel lies in the fact that it takes care of placing AJAX calls, updating the ViewState and doing partial rendering with out us having to write a single piece of javascript.&lt;br /&gt;&lt;br /&gt;To drive home the point, let us create a simple ASP.NET project.&lt;br /&gt;The project will have have one webform (Default.aspx) with a GridView control in it.&lt;br /&gt;The GridView will display a list of customers from a database (ShoppinCart).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Create the Database&lt;/strong&gt;&lt;br /&gt;Please create a database with the name ShopoingCart and a table called Customer in that database. The customer table will have the following columns. Add those columns and populate the table with some data. (CustomerId, FirstName, LastName, Phone, Email)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Create the Project&lt;br /&gt;&lt;/strong&gt;Open Visual Studio 2005 and create a new project of type ASP.NET AJAX-Enabled Web Application. Name the project AJAXTest.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Add the connection string to Web.config&lt;/strong&gt; (Modify the connection string accordingly)&lt;br /&gt;&lt;textarea style="WIDTH: 568px; HEIGHT: 77px" rows="3" cols="61"&gt;&lt;connectionstrings&gt;&lt;br /&gt; &lt;add name="ShoppingCartConnString" connectionstring="data source=Kode-Cruncher\SQLEXPRESS;database=ShoppingCart;integrated security=true"&gt;&lt;br /&gt;&lt;/connectionstrings&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Add UpdatePanel to the webform&lt;/strong&gt;&lt;br /&gt;On to your Default.aspx page, drag and drop an UpdatePanel control from the tool box (under AJAX Extension tab)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Drag and drop GridView&lt;/strong&gt;&lt;br /&gt;Drag and drop a &lt;strong&gt;&lt;em&gt;gridview&lt;/em&gt;&lt;/strong&gt; into the updatepanel. Also drag and drop &lt;strong&gt;&lt;em&gt;SqlDataSource&lt;/em&gt;&lt;/strong&gt; control inside the update panel. If you created the database and customer table as directed above, your can replace your update panel with the code below.&lt;br /&gt;&lt;br /&gt;&lt;textarea style="WIDTH: 573px; HEIGHT: 310px" rows="10" cols="62" runat="server"&gt; &lt;contenttemplate&gt;&lt;br /&gt; &lt;asp:gridview id="grdCustomers" autogeneratecolumns="false" runat="server" datakeynames="CustomerId" datasourceid="sdsCustomers"&gt; &lt;columns&gt; &lt;br /&gt;  &lt;asp:boundfield datafield="CustomerId" headertext="Customer Id" readonly="true"&gt; &lt;asp:boundfield datafield="FirstName" headertext="First Name"&gt; &lt;asp:boundfield datafield="LastName" headertext="Last Name"&gt; &lt;asp:boundfield datafield="Phone" headertext="Phone"&gt; &lt;asp:boundfield datafield="Email" headertext="Email"&gt; &lt;asp:commandfield headertext="Edit" showeditbutton="true"&gt; &lt;asp:commandfield headertext="Delete" showdeletebutton="true"&gt;&lt;br /&gt; &lt;/columns&gt;&lt;br /&gt;&lt;/asp:GridView&gt; &lt;br /&gt;&lt;br /&gt;&lt;asp:sqldatasource id="sdsCustomers" runat="server" providername="System.Data.SqlClient" connectionstring=""&gt;"   SelectCommand="SELECT * FROM [Customer]"UpdateCommand="UPDATE [Customer] SET   FirstName=@FirstName,LastName=@LastName,Email=@Email,Phone=@Phone WHERE   CustomerId=@CustomerId"DeleteCommand="DELETE FROM [Customer] WHERE   customerId=@CustomerId"&gt; &lt;br /&gt;&lt;/asp:SqlDataSource&gt;&lt;br /&gt;&lt;/contenttemplate&gt; &lt;br /&gt;&lt;/asp:UpdatePanel&gt; &lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;contenttemplate&gt;&lt;strong&gt;Test the Page&lt;/strong&gt;&lt;br /&gt;Set default.aspx as your start page and run the project. As you click edit, updata and delete controls in the grid, you should&lt;br /&gt;notice that your page does not do a full refresh, only the grid is updated.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;We have seen how easy it is to add AJAX functionality to your webform with update panel contro. In the next article I will demonstrate&lt;br /&gt;how to call web services with Atlas.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-7559705732573251314?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/7559705732573251314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=7559705732573251314' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/7559705732573251314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/7559705732573251314'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/02/getting-started-with-aspnet-ajax.html' title='Getting Started with ASP.NET AJAX'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-117021103384126090</id><published>2007-01-30T18:05:00.000-08:00</published><updated>2007-01-30T18:56:02.686-08:00</updated><title type='text'>Attended Windows Vista and Office 2007 launch</title><content type='html'>Today I attended Windows Vista and Office 2007 launch in Washington D.C.&lt;br /&gt;The event took place in Washington Hilton hotel.&lt;br /&gt;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.&lt;br /&gt;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.&lt;br /&gt;Finally as an incentive to attending the conference each of us received an Office 2007 copy and a T-shirt.&lt;br /&gt;&lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/327466/IMG_2422.jpg"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger/5463/3968/320/546749/IMG_2422.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Microsoft has put up a new &lt;a href="http://www.dinnernow.net/"&gt;website&lt;/a&gt; (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.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-117021103384126090?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/117021103384126090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=117021103384126090' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/117021103384126090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/117021103384126090'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/attended-windows-vista-and-office-2007.html' title='Attended Windows Vista and Office 2007 launch'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-117013230146068922</id><published>2007-01-29T20:30:00.000-08:00</published><updated>2007-01-29T20:45:01.473-08:00</updated><title type='text'>Error "The project type is not supported by this installation." while creating ASP.NET AJAX enabled Web Application</title><content type='html'>Last night I downloaded and installed ASP.NET 2.0 AJAX Extensions 1.0 on my home computer. When AJAX extensions are installed, &lt;strong&gt;&lt;em&gt;ASP.NET AJAX Enabled Web Application &lt;/em&gt;&lt;/strong&gt;project template is also installed.&lt;br /&gt;I tried creating a new project by selecting &lt;strong&gt;ASP.NET AJAX Enabled Web Application &lt;/strong&gt;and I got an error some thing like below.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size:85%;color:#3366ff;"&gt;The project file 'C:\Inetpub\wwwroot\.....\AJAXTest.vbproj' cannot be opened.&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size:85%;color:#3366ff;"&gt;The project type is not supported by this installation.&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size:85%;color:#3366ff;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;span style="color:#330033;"&gt;Upon Googling a bit, I found that we need to install &lt;strong&gt;Visual Studio 2005 Web Application project.&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#330033;"&gt;and &lt;strong&gt;VS 2005 hot fix&lt;/strong&gt; to support Visual Studio 2005 Web Application project. The hot fix should be installed first.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#330033;"&gt;Please follow the link to learn more.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#330033;"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx"&gt;http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#330033;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#330033;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-117013230146068922?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/117013230146068922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=117013230146068922' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/117013230146068922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/117013230146068922'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/error-project-type-is-not-supported-by.html' title='Error &quot;The project type is not supported by this installation.&quot; while creating ASP.NET AJAX enabled Web Application'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-117002028893053139</id><published>2007-01-28T13:22:00.000-08:00</published><updated>2007-01-28T14:27:55.660-08:00</updated><title type='text'>Rare Videos of Warren Buffet</title><content type='html'>I was browsing throught Google Videos today and came across some videos on Warren Buffet.&lt;br /&gt;The videos talk about Warren Buffet's life, his investment philosophy, his friend ship with Charlie Munger and Bill Gates and his philanthropy. I have read a book on Warren Buffet but haven't seen him talk till now. The videos are made by Charlie Rose in an interactive way and are very engaging even if you do not know anything about Warren Buffet. I have learned a lot from these videos.&lt;br /&gt;&lt;br /&gt;This video talks about Buffet's childhood, his family and marriage .&lt;br /&gt;&lt;a href="http://video.google.com/videoplay?docid=6701318343299922276"&gt;http://video.google.com/videoplay?docid=6701318343299922276&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This video talk about how Buffet made his billions&lt;br /&gt;&lt;a href="http://video.google.com/videoplay?docid=-6208910876057109785&amp;q=label%3A%22warren+buffett%22"&gt;http://video.google.com/videoplay?docid=-6208910876057109785&amp;amp;q=label%3A%22warren+buffett%22&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This video talks about his friendship with Bill Gates and his charity gift to Bill &amp;Melinda Gates foundation.&lt;br /&gt;&lt;a href="http://video.google.com/videoplay?docid=-4846290947664386236&amp;amp;amp;q=label%3A%22warren+buffett%22"&gt;http://video.google.com/videoplay?docid=-4846290947664386236&amp;amp;q=label%3A%22warren+buffett%22&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-117002028893053139?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/117002028893053139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=117002028893053139' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/117002028893053139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/117002028893053139'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/rare-videos-of-warren-buffet.html' title='Rare Videos of Warren Buffet'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116965705834758805</id><published>2007-01-24T08:31:00.000-08:00</published><updated>2007-01-25T13:59:33.930-08:00</updated><title type='text'>A very useful Habit Tracking Application.</title><content type='html'>I ran across Joe's Goal Tracking Application on Delicious and I fell in love with it.It is one of those AJAX applications out there that is really useful and easy to use. It helps you keep track of your goals and even gives u reports on your progress. I recommend you give it a try. Here is a screen shot of my goals. You can find the app at http://joesgoals.com&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/243764/capture2.jpg"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger/5463/3968/400/473998/capture2.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/397264/capture2.jpg"&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116965705834758805?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116965705834758805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116965705834758805' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116965705834758805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116965705834758805'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/very-useful-habit-tracking-application.html' title='A very useful Habit Tracking Application.'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116952604653865940</id><published>2007-01-22T20:18:00.000-08:00</published><updated>2007-01-22T20:22:48.616-08:00</updated><title type='text'>Cheat Sheets for client side JavaScript Extensions for Microsoft AJAX Library</title><content type='html'>You can download cool cheat sheets for ASP.NET client side javascript extensions here&lt;br /&gt;&lt;a href="http://aspnetresources.com/blog/ms_ajax_cheat_sheets_batch1.aspx"&gt;http://aspnetresources.com/blog/ms_ajax_cheat_sheets_batch1.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116952604653865940?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116952604653865940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116952604653865940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116952604653865940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116952604653865940'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/cheat-sheets-for-client-side.html' title='Cheat Sheets for client side JavaScript Extensions for Microsoft AJAX Library'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116922877319753337</id><published>2007-01-19T09:21:00.000-08:00</published><updated>2007-01-22T08:57:38.320-08:00</updated><title type='text'>WSE2 Tracing SOAP messages</title><content type='html'>Microsoft Web Services Enhancements (WSE 2.0) allows you to trace incoming and out going SOAP message. &lt;strong&gt;Monitor the trace files and purge the files before they become too big&lt;/strong&gt;. If the files get too big, WSE 2.0 throws all kind of communication errors.&lt;br /&gt;&lt;br /&gt;My webservice is behind a firewall and is hosted in a windows service on a particular port (xxxx). The client (outside the firewall) communicates with the windows service over TCP.&lt;br /&gt;&lt;br /&gt;One fine day, the communication between the client and service broke. I found the following stack trace in my log file. From the stack trace, my initial thought was the service might be down and verfied the service to be running. Next, I connected my local system to the service and verfied that the communicate is fine. Since the service is running properly, I verified with the sys admin that the port (xxxx) on the router is mapped correctly to the server hosting the webservice.&lt;br /&gt;&lt;br /&gt;After banging my head and Googling for hours I could not come up with a definite reason on why the client could not communicate with the service. When I tried to open the trace files on the client, I realised them to be too big and right then I had that AHA moment. I went ahead and disabled WSE SOAP message tracing and you got it right, the app is back on its feet smiling.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size:85%;color:#6633ff;"&gt;Error Message:Write Failure: &lt;span style="color:#ff6600;"&gt;Socket is not connected&lt;/span&gt;Stack Trace:Server stack trace: at Microsoft.Web.Services2.Messaging.SoapTcpNetworkStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state) at Microsoft.Web.Services2.Messaging.SoapTcpNetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count) at Microsoft.Web.Services2.Dime.DimeRecord.WriteHeader(Boolean endOfRecord, Int64 contentLength) at Microsoft.Web.Services2.Dime.DimeRecord.WriteChunkedPayload(Boolean endOfRecord, Boolean endOfMessage, Byte[] bytes, Int32 offset, Int32 count) at Microsoft.Web.Services2.Dime.DimeRecord.WriteChunkedPayload(Boolean endOfRecord, Boolean endOfMessage) at Microsoft.Web.Services2.Dime.DimeRecord.Close(Boolean endOfMessage) at Microsoft.Web.Services2.Dime.DimeWriter.Close() at Microsoft.Web.Services2.Messaging.SoapDimeFormatter.Microsoft.Web.Services2.Messaging.ISoapFormatter.Serialize(SoapEnvelope envelope, Stream stream) at Microsoft.Web.Services2.Messaging.SoapTcpConnection.SerializeMessage(SoapEnvelope envelope) at Microsoft.Web.Services2.Messaging.SoapTcpOutputChannel.Send(SoapEnvelope message) at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]&amp; outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)&lt;br /&gt;Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase) at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData&amp;amp; msgData) at Microsoft.Web.Services2.Messaging.SendDelegate.EndInvoke(IAsyncResult result) at Microsoft.Web.Services2.Messaging.SoapOutputChannel.EndSend(IAsyncResult result) at Microsoft.Web.Services2.Messaging.SoapSender.EndSend(IAsyncResult result) at Microsoft.Web.Services2.Messaging.SoapClientAsyncResult.OnSendComplete(IAsyncResult result)&lt;/span&gt;&lt;/em&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116922877319753337?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116922877319753337/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116922877319753337' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116922877319753337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116922877319753337'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/wse2-tracing-soap-messages.html' title='WSE2 Tracing SOAP messages'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116904805791671159</id><published>2007-01-17T07:10:00.000-08:00</published><updated>2007-01-17T07:34:18.310-08:00</updated><title type='text'>Successfully installed and implemented Google Mini</title><content type='html'>Google Mini is Google's integrated hardware and software solution to index your organization's digital assets. You can learn more about Google Mini here &lt;a href="http://www.google.com/enterprise/mini/"&gt;http://www.google.com/enterprise/mini/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Earlier our client, was using Microsoft's Index Server to index their digital assets. This index server was shared by several websites and is slowing things a bit. The server, I guess reached its capacity and could not crawl and index any new files added. We were looking at alternative solutions and stumbled upon the &lt;strong&gt;Mini. &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Google Mini is a powerful search appliance in a blue box of the size  of a large Pizza Hut pizza box. It is very easy to set it up and configure. The whole things takes around an hour or so to have the basic search solution up and running.  All you have to do, is to tell the &lt;strong&gt;Mini  &lt;/strong&gt;what URL paths it has to index and bang, the Mini is on its feet crawling the site.&lt;br /&gt;&lt;br /&gt;Things get a little tough and confusing when you start to change the look and feel of the results. To change the look and feel of the search results, we got to modify the style sheet (XSLT) that Google Appliance uses. In that we can configure our own header, menu and footer to integrate the search solution within the corporate website. This might take a while but trust me it is easy if you know how to tweak the XSLT. We can have more than one look and feel( front end) for our search results. Google Mini also lets us define our own collections to have pointed searches. A collection is a set of URL paths.&lt;br /&gt;&lt;br /&gt;You can find the solution we implementd here &lt;a href="http://search.dcoz.dc.gov/"&gt;http://search.dcoz.dc.gov/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Overall, we are extremely satisfied with the end result. The search is very fast and the Return on Investment  is huge.&lt;br /&gt;&lt;br /&gt;If you have any questions on Google Mini, please leave a comment and I'll be glad to help you out.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116904805791671159?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116904805791671159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116904805791671159' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116904805791671159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116904805791671159'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/successfully-installed-and-implemented.html' title='Successfully installed and implemented Google Mini'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116870683657498902</id><published>2007-01-13T07:50:00.000-08:00</published><updated>2007-01-13T08:58:52.933-08:00</updated><title type='text'>Using CASE, WHEN in SQL Server 2000</title><content type='html'>&lt;strong&gt;CASE expression&lt;/strong&gt; in SQL Server is very useful and can save you hours of time.&lt;br /&gt;&lt;br /&gt;In my project, I had to update a column in a table with several thousands of rows. My task is to remove a prefix (ANC) from the data in the column.&lt;br /&gt;For example, the data in the column looks like below. I want to remove ANC and the following hyphen or space from all the rows in that column.&lt;br /&gt;ANC-1E01&lt;br /&gt;ANC2B02&lt;br /&gt;ANC 3C01&lt;br /&gt;3C01&lt;br /&gt;2E&lt;br /&gt;Null&lt;br /&gt;&lt;br /&gt;My intial thought was to update the table manually, but with the sheer amount of rows in the table that approach seemed humungous.&lt;br /&gt;&lt;br /&gt;Second thought was to write a cursor to loop through the table and update each row. But I thought there should be a better approach.&lt;br /&gt;&lt;br /&gt;On brainstorming a bit, the &lt;strong&gt;&lt;span style="color:#ff9900;"&gt;CASE expression&lt;/span&gt;&lt;/strong&gt; in SQL Server came to my rescue. It offered me a simple and elegant solution.&lt;br /&gt;&lt;br /&gt;Here is how I updated my table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;UPDATE WARDDetails&lt;br /&gt;SET Ward=&lt;br /&gt;CASE&lt;br /&gt;WHEN charIndex('ANC-',Ward)&gt;0 --&lt;em&gt;&lt;strong&gt;&lt;span style="font-size:78%;color:#3366ff;"&gt;If the data is like ANC-XXX remove 'ANC-'&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;THEN SUBSTRING(Ward,charIndex('ANC-',Ward)+4,len(Ward))&lt;br /&gt;WHEN charIndex('ANC ',Ward)&gt;0 &lt;em&gt;&lt;strong&gt;&lt;span style="font-size:78%;color:#3366ff;"&gt;--If the data is like ANC XXX remove 'ANC '&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;THEN SUBSTRING(Ward,charIndex('ANC- ',Ward)+4,len(Ward))&lt;br /&gt;WHEN charIndex('ANC ',Ward)&gt;0 &lt;strong&gt;&lt;em&gt;&lt;span style="font-size:78%;color:#3366ff;"&gt;--If the data is like ANCXXX remove 'ANC'&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;THEN SUBSTRING(Ward,charIndex('ANC',Ward)+4,len(Ward))&lt;br /&gt;ELSE Ward &lt;strong&gt;&lt;em&gt;&lt;span style="font-size:78%;color:#3366ff;"&gt;--If none of the above, dont update&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116870683657498902?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116870683657498902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116870683657498902' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116870683657498902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116870683657498902'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2007/01/using-case-when-in-sql-server-2000.html' title='Using CASE, WHEN in SQL Server 2000'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116708312377686782</id><published>2006-12-25T13:45:00.000-08:00</published><updated>2006-12-31T19:39:25.566-08:00</updated><title type='text'>Uploading files to the server like GMail and Yahoo Mail</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Recently I got to work on a project which needed file uploading just like in GMail and Yahoo Mail. Before proceeding further, I would like to mention that it is not possible to use AJAX to do file uploading to ther server as JavaScript can execute only in the browser and does not have access to the file system. So the technique we employed here is the the &lt;strong&gt;hidden IFrame&lt;/strong&gt; .&lt;/p&gt;&lt;br /&gt;&lt;p&gt;To make this work we need JavaScript and any server side script. For the demo, I will be using ASP.NET with C# on the server side. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Let us delve in to the code without further delay. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; In your web application, create two aspx files UploadTest.aspx and UploadFile.aspx.&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 2: &lt;/strong&gt;Add this HTML code inside form tag to UploadTest.aspx&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;table id="tblAttach"&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;tr&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;!--- This td displays the link Attach File--&amp;gt; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td id="td_upload_attach" style="DISPLAY: block;&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/td&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;!--This td displays the attaching message while the file is uploading to ther server--&amp;gt; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td id="td_upload_attaching" style="DISPLAY: none"&amp;gt; &amp;lt;/td&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;!--This td displays the attached file--&amp;gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td id="td_upload_fileName" style="DISPLAY: none"&amp;gt;&amp;lt;/td&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;!--This td displays the Remove Link--&amp;gt; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td id="td_upload_remove" style="DISPLAY: none"&amp;gt;&amp;lt;/td&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/tr&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/table&amp;gt;&lt;/em&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 3: &lt;/strong&gt;Update the first td to add an image &lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/905959/paperclip.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger/5463/3968/200/342208/paperclip.gif" border="0" /&gt;&lt;/a&gt;and Attach File link and hidden IFrame. Clicking on Attach File link will call the javascript function AttachFile() (&lt;em&gt;&lt;strong&gt;&lt;span style="font-size:85%;"&gt;discussed later&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;). &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The hidden IFrame's source is set UploadFile.aspx that we created above.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td style="DISPLAY: block;" id="td_upload_attach"&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;table width="100" border="0" cellpadding="2" cellspacing="0"&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;tr&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td width="16"&amp;gt;&amp;lt;img src="paperclip.gif" width="16" height="16"&amp;gt;&amp;lt;/td&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td nowrap align="left" class="blackFormText2"&amp;gt;&amp;lt;a href="#" tabindex="12" class="blackFormText2" onclick="AttachFile();"&amp;gt;Attach File&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;/tr&amp;gt; &amp;lt;/table&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;/em&gt;&lt;strong&gt;&lt;span style="color:#ff6600;"&gt;&amp;lt;iframe id="iFrameUpload" style="DISPLAY: none;" width="50" height="50" align="top" marginWidth="1" marginHeight="1" frameBorder="no" scrolling="no" src="UploadFile.aspx"&amp;gt; &lt;/span&gt;&lt;em&gt;&lt;span style="color:#ff8000;"&gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/td&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 4: &lt;/strong&gt;Update the second td to add code that displays a rotating icon &lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/708361/loading_small.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger/5463/3968/200/485751/loading_small.gif" border="0" /&gt;&lt;/a&gt; and a message &lt;strong&gt;attaching...&lt;/strong&gt; while the file is uploading to the server.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;table width="100" border="0" cellpadding="2" cellspacing="0"&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;tr&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td width="16"&amp;gt;&amp;lt;img src="loading_small.gif" width="16" height="16"&amp;gt;&amp;lt;/td&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td nowrap class="blackFormText" style="WHITE-SPACE:nowrap"&amp;gt;&amp;lt;span id="span_upload_attaching"&amp;gt;Attaching...&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/tr&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/table&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 5: &lt;/strong&gt;Update the third td to add an image &lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/212493/attached.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger/5463/3968/200/514321/attached.gif" border="0" /&gt;&lt;/a&gt; and the attached file name.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;table width="100" border="0" cellpadding="2" cellspacing="0"&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;tr&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td width="16"&amp;gt;&amp;lt;img src="attached.gif" width="14" height="16"&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;td nowrap class="blackFormText2"&amp;gt;&amp;lt;span id="span_upload_fileName"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;/tr&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/table&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 6: &lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/115894/remove.gif"&gt;&lt;/a&gt;&lt;/strong&gt;Update the fourth td to add a remove image &lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/778453/remove.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger/5463/3968/200/409143/remove.gif" border="0" /&gt;&lt;/a&gt; and a link to remove the attached file.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td id="td_upload_remove" style="DISPLAY: none"&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;table width="100" border="0" cellpadding="2" cellspacing="0"&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;tr&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td width="16"&amp;gt;&amp;lt;img src="remove.gif" width="14" height="16"&amp;gt;&amp;lt;/td&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;td nowrap class="blackFormText2"&amp;gt;&amp;lt;a tabindex="12" href="#" class="blackFormText" onclick="RemoveFile();"&amp;gt;Remove File&amp;lt;/a&amp;gt; &amp;lt;/td&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/tr&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/table&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/td&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;strong&gt;Step 7: &lt;/strong&gt;Now, let us discuss the javascript needed to accomplish our task. Add javascript script block inside the head section of the web form. Add two variable fileId and fileName;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;Script language="javascript"&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;var fileId=-1;&lt;/p&gt;&lt;p&gt;var fileName="";&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/Script&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 8: &lt;/strong&gt;Add the function AttachFile() inside the javascript block. When the user clicks the Attach File link, this function is called. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;function AttachFile()&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var uploadFrame=window.frames["iFrameUpload"].document;&lt;span style="color:#ff8000;"&gt; &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;span style="color:#ff8000;"&gt;uploadFrame.forms[0].txtFileToUpload.click();&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;span style="color:#ff8000;"&gt;&lt;/span&gt;if(uploadFrame.forms[0].txtFileToUpload.value!='')&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var filePath=uploadFrame.forms[0].txtFileToUpload.value;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var fileNameIndexStart=filePath.lastIndexOf("//");&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var fileName=filePath.substring(fileNameIndexStart+1,filePath.length); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;document.getElementById('td_upload_attach').style.display='none'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;document.getElementById('span_upload_attaching').innerHTML= &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;'attaching... '+fileName; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;document.getElementById('td_upload_attaching').style.display='block'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;uploadFrame.forms[0].submit();&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 9: &lt;/strong&gt;Add the function AttachFile_Callback(). This function is called by the UploadFile.aspx after attaching the file. Any errors reported by the UploadFile.aspx, are displayed to ther user.&lt;/p&gt;&lt;p&gt;Error Ids are set on the server side when an error is encounterd. (Discussed on Step 17)&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;function AttachFile_Callback(errorId,id,name)&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;if(errorId.length&amp;gt;0) &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;document.getElementById('td_upload_attach').style.display='block'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;document.getElementById('td_upload_attaching').style.display='none'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;switch(errorId)&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{ case "1": window.parent.alert("Please select a file to upload"); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;break;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;case "2": window.parent.alert("The uploaded file is empty"); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;break; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;case "3": window.parent.alert("The uploaded file is too big. The file size cannot be greater than 5 MB."); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;break;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;case "4": window.parent.alert("Sorry, an unexpected error occurred uploading the file."); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;break;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;else if(id!="-1")&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{ &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;fileId=id; //set the file Id; fileName=name; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var spanFileName=document.getElementById('span_upload_fileName'); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;if(spanFileName!=null)&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{ spanFileName.innerHTML=name; } &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;ShowUploadLink(false);&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;em&gt;&lt;span style="color:#0000ff;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 10: &lt;/strong&gt;Add the function RemoveFile(). This shows the attach file link again. I have not added code to remove the file on the server. If necessary you can add that here. You can pass the id of the file that we put in the global variable fileId to the server.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;function RemoveFile() { ShowUploadLink(true); }&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 11: &lt;/strong&gt;Add the function ShowUploadLink(). This is a helper function to show and hide &amp;lt;td&amp;gt;s in the table.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;function ShowUploadLink(flag)&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var tdAttach=document.getElementById('td_upload_attach');&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var tdAttaching=document.getElementById('td_upload_attaching');&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var tdFileName=document.getElementById('td_upload_fileName'); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var tdRemove=document.getElementById('td_upload_remove');&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;if(flag)&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{ &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;tdAttach.style.display='block'; tdAttaching.style.display='none'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;tdFileName.style.display='none'; tdRemove.style.display='none'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;else&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{ tdAttach.style.display='none'; tdAttaching.style.display='none'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;tdFileName.style.display='block'; tdRemove.style.display='block'; &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var spanFileName=document.getElementById('span_upload_fileName'); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;if(spanFileName!=null)&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{ spanFileName.innerHTML=fileName; }&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;&lt;span style="color:#000000;"&gt;Step 12:&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="color:#000000;"&gt;Now let us add code to the UploadFile.aspx. Add an input of type file.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;table width="100%" border="0" cellpadding="6" cellspacing="0" bgcolor="#e1ecf2" summary="This table is for layout"&amp;gt;&lt;br /&gt;&amp;lt;tr&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt; &amp;lt;td valign="top"&amp;gt;&lt;br /&gt;&amp;lt;input class="blueFormText" id="txtFileToUpload" title="File to Upload" &lt;/em&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;tabindex="200" type="file" size="30" name="filMyFile" runat="server" style="WIDTH: 275px; HEIGHT: 22px"&amp;gt;&lt;br /&gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 13:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Add three hidden variables to the web form.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;INPUT id="hidFileName" type="hidden" runat="server" NAME="hidFileName" class="blueFormText"&amp;gt; &amp;lt;INPUT type="hidden" runat="server" id="hidFileId" NAME="hidFileId" class="blueFormText" value=-1&amp;gt; &amp;lt;INPUT id="hidErrorId" type="hidden" runat="server"&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 14:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;To the body tag of the web form add onload event.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;body MS_POSITIONING="GridLayout" onload="CheckFileId();"&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 15:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Add the javascript function that is called by onload event. This function calls AttachFile_Callback function we added above when ever this page is loaded in the browser.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;script language="javascript"&amp;gt; &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;function CheckFileId() &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;{&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var hidErrorId=document.getElementById('hidErrorId'); &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var hidFile=document.getElementById('hidFileId'); &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;var hidFileName=document.getElementById('hidFileName'); &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;span style="color:#ff8000;"&gt;&lt;strong&gt;window.parent.AttachFile_Callback (hidErrorId.value,hidFile.value,hidFileName.value); } &lt;/strong&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&amp;lt;/script&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 16:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="color:#333333;"&gt;In the code behind of the UploadFile.aspx, in Page_Load(), I check if the page is posted back and call the UploadFile function that takes cared of adding the file to the database.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;private void Page_Load(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;if(Page.IsPostBack)&lt;br /&gt;UploadFile();&lt;br /&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 17:&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Add code for UploadFile server side function. The function checks for erorrs like 0 length, more than 5 MB and unexpected errors. If no errors file is put into the database.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;private void UploadFile()&lt;br /&gt;{&lt;br /&gt;//check if the user selected a file.&lt;br /&gt;if(txtFileToUpload.PostedFile.FileName.Trim() == null txtFileToUpload.PostedFile.FileName.Trim().Length == 0)&lt;br /&gt;{&lt;br /&gt;hidErrorId.Value="1";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;int intDocLen = txtFileToUpload.PostedFile.ContentLength;&lt;br /&gt;if(intDocLen==0)&lt;br /&gt;{&lt;br /&gt;hidErrorId.Value="2";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;if(intDocLen&amp;gt;5000000)&lt;br /&gt;{&lt;br /&gt;//Response.Write("Please limit the file size to 5MB.");&lt;br /&gt;hidErrorId.Value="3";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;string fileName=System.IO.Path.GetFileName(txtFileToUpload.PostedFile.FileName);&lt;br /&gt;int fileLength=txtFileToUpload.PostedFile.ContentLength;&lt;br /&gt;string fileType=txtFileToUpload.PostedFile.ContentType;&lt;br /&gt;byte[] fileBin=new byte[fileLength];&lt;br /&gt;System.IO.Stream stream = txtFileToUpload.PostedFile.InputStream;&lt;br /&gt;stream.Read(fileBin,0,fileLength);&lt;br /&gt;string connstr=util.WebConfigReader.GetAppSetting(model.Constants.CONNECTION_STRING_KEY); &lt;span style="color:#ff8000;"&gt;//change connection string&lt;/span&gt;&lt;br /&gt;SqlConnection connection = new SqlConnection(connstr);&lt;br /&gt;string sql="INSERT Into FileTable(FileName,Filetype,FileBin)Values(@FileName,@FileType,@FileBin);SELECT SCOPE_IDENTITY();"&lt;br /&gt;SqlCommand insertCommand = new SqlCommand(sql,connection); &lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;SqlParameter fileNameParam = new SqlParameter("@FileName", SqlDbType.VarChar);&lt;br /&gt;fileNameParam.Value = fileName;&lt;br /&gt;insertCommand.Parameters.Add(fileNameParam); &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;SqlParameter fileTypeParam = new SqlParameter("@FileType", SqlDbType.VarChar);&lt;br /&gt;fileTypeParam.Value = fileType;&lt;br /&gt;insertCommand.Parameters.Add(fileTypeParam); &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;SqlParameter fileBinParam = new SqlParameter("@FileBin", SqlDbType.Image);&lt;br /&gt;fileBinParam.Value = fileBin;&lt;br /&gt;insertCommand.Parameters.Add(fileBinParam); &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;connection.Open();&lt;br /&gt;string fileId = insertCommand.ExecuteScalar().ToString();;&lt;br /&gt;connection.Close(); &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;strong&gt;&lt;span style="color:#ff9900;"&gt;hidFileId.Value=fileId;&lt;/span&gt;&lt;/strong&gt; &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;span style="color:#ff9900;"&gt;&lt;strong&gt;hidFileName.Value=fileName;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;hidErrorId.Value="4";&lt;br /&gt;}&lt;br /&gt;}&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116708312377686782?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116708312377686782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116708312377686782' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116708312377686782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116708312377686782'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2006/12/uploading-files-to-server-like-gmail_25.html' title='Uploading files to the server like GMail and Yahoo Mail'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116698157743185062</id><published>2006-12-24T07:33:00.000-08:00</published><updated>2007-10-22T13:50:52.203-07:00</updated><title type='text'>Kill a remote user session remotely</title><content type='html'>When trying to connect to your Windows 2000/2003 server remotely, you may receive the following error.&lt;br /&gt;&lt;strong&gt;"The terminal server has exceeded the maximum number of allowed connections."&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You could kill one or more of those connections by using &lt;strong&gt;PsExec&lt;/strong&gt; tool that can be downloaded from the following link. This tool and a bunch of others were developed by SysInternals which was bought by Microsoft.&lt;br /&gt;&lt;a href="http://www.microsoft.com/technet/sysinternals/utilities/pstools.mspx"&gt;http://www.microsoft.com/technet/sysinternals/utilities/pstools.mspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Open your command prompt and from the directory that contains the psexec utility, do the following&lt;br /&gt;&lt;br /&gt;1) psexec \\x.x.x.x -u user -p password cmd &lt;strong&gt;&lt;em&gt;&lt;span style="font-size:78%;"&gt;(this will give you access to the cmd prompt on the server)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;Example: psexec \\127.0.0.1 -u admin -p password cmd&lt;br /&gt;&lt;br /&gt;2) once you get the command prompt run the command &lt;strong&gt;qwinsta &lt;/strong&gt;to get a list of all Terminal Services connections. Each connection has an Id Number.&lt;br /&gt;&lt;br /&gt;3) Run the command logoff [id# of session to quit] /v &lt;span style="font-size:78%;"&gt;&lt;strong&gt;(this will kill the connection with that id #)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;Example: logoff 2 /v&lt;br /&gt;&lt;br /&gt;Once you killed a connection, you can use your remote desktop connection to login to the server remotely.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116698157743185062?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116698157743185062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116698157743185062' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116698157743185062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116698157743185062'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2006/12/kill-remote-user-session-remotely.html' title='Kill a remote user session remotely'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35631598.post-116018439866823625</id><published>2006-10-06T18:25:00.000-07:00</published><updated>2007-01-26T11:45:46.790-08:00</updated><title type='text'>Welcome to my blog</title><content type='html'>&lt;a href="http://photos1.blogger.com/x/blogger/5463/3968/1600/248012/capture1.jpg"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger/5463/3968/320/840083/capture1.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/blogger/5463/3968/1600/IMG_1310.jpg"&gt;&lt;img style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://photos1.blogger.com/blogger/5463/3968/320/IMG_1310.jpg" border="0" /&gt;&lt;/a&gt; Welcome to my blog. I will use this blog to write just about everything I could think of. Stay tuned ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35631598-116018439866823625?l=kodethoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kodethoughts.blogspot.com/feeds/116018439866823625/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35631598&amp;postID=116018439866823625' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116018439866823625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35631598/posts/default/116018439866823625'/><link rel='alternate' type='text/html' href='http://kodethoughts.blogspot.com/2006/10/welcome-to-my-blog.html' title='Welcome to my blog'/><author><name>Kotendra Kode</name><uri>http://www.blogger.com/profile/01657082565105290045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
