<?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-8567593552832750240</id><updated>2011-11-07T22:35:36.820-05:00</updated><title type='text'>Fantastic Programming Adventures</title><subtitle type='html'>Tips and Tricks on ASP.Net and C# Programming</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://beakdev.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://beakdev.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Chris Thomson</name><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>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8567593552832750240.post-6580236713074615923</id><published>2010-11-24T11:24:00.004-05:00</published><updated>2010-11-24T11:42:38.593-05:00</updated><title type='text'>Accents clipped off text in IE7 and IE8 with Compatibility Mode</title><content type='html'>As I work in Canada, which is a bilingual country, the applications I develop usually have to be available in both English and French.  Today I had a rather odd problem regarding accented characters with missing accents.&lt;br /&gt;&lt;br /&gt;The character in question was an 'É' and I had a bug where the accent was missing.  My first call was the database to check the accent was there, and it was.  So I thought it was being lost due to some difference of character set between database and application layer, but breakpoints showed it was all correct at the application layer.  Next I checked the source for the rendered web page and that showed the accent was there too.  I even tried a copy and paste of the text and pasting the text into an editor showed the accent was present, even though it was missing in the browser.&lt;br /&gt;&lt;br /&gt;Some more tests revealed that the accent displayed correctly in IE8 with Compatibility Mode disabled, but when Compatibility Mode was enabled the accent was clipped off.  I spent some time adjusting parameters on the ASP.Net Label control and at higher levels in the mark up to get the height to increase with no more result that lots of whitespace but no accent.  I was able to get the accent to appear by sacrificing the bottom few pixels of the text when setting the valign property, but this clearly wasn't acceptable.  By making the text size 11 or smaller the accent appeared, but at 12 or above it was missing.&lt;br /&gt;&lt;br /&gt;After some more searching I eventually found the CSS property to fix it.  By adding "Font" tags around the label and applying "&lt;span style="font-weight: bold;"&gt;line-height: 1.1;&lt;/span&gt;" to the style I got it to display the accent correctly.&lt;br /&gt;&lt;br /&gt;It seems that in the IE8 beta, Compatibility Mode was actually called IE7 Emulation Mode, a name which they really should have kept as "Compatibility" is more suggestive of standards compliance which is exactly what Compatibility Mode/IE7 Emulation Mode/IE7 is NOT.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8567593552832750240-6580236713074615923?l=beakdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beakdev.blogspot.com/feeds/6580236713074615923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://beakdev.blogspot.com/2010/11/accents-clipped-off-text-in-ie7-and-ie8.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/6580236713074615923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/6580236713074615923'/><link rel='alternate' type='text/html' href='http://beakdev.blogspot.com/2010/11/accents-clipped-off-text-in-ie7-and-ie8.html' title='Accents clipped off text in IE7 and IE8 with Compatibility Mode'/><author><name>Chris Thomson</name><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-8567593552832750240.post-5333956807844340093</id><published>2010-11-09T14:47:00.008-05:00</published><updated>2010-11-09T16:17:55.385-05:00</updated><title type='text'>Javascript popup appears again when back button pressed</title><content type='html'>One of the bugs I was looking at today was regarding use of the back button in our webapp.  We have a screen that lets the user enter some data and click submit.  The server side validates that data, and if necessary it alerts the user of errors using a alert issued with &lt;span style="font-weight: bold;"&gt;RegisterStartupScript&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;If the user gets the error, corrects there input data, then resubmits they will be taken to the next page in the process.  The problem comes when they click the back button.  When the back button is pressed it takes them back to the first page which still has the startup script in it, causing the old validation error popup to appear again.&lt;br /&gt;&lt;br /&gt;I did a lot of searching on this to see if there was a simple solution.  I discovered the following:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;There is no simple way to "unregister" a startup script.&lt;/li&gt;&lt;li&gt;Ideally the popup should be generated inside an onclick event, but this  wasn't possible in my case due to the server side validation.&lt;/li&gt;&lt;li&gt;The first webpage can be set to expire, but this causes a "webpage expired" page to be displayed, which isn't any use.&lt;/li&gt;&lt;li&gt;The popup button can be pseudo disabled but that doesn't afford the user the behavior they expect.&lt;/li&gt;&lt;li&gt;Meta tags can be used to force a page to always refresh, rather than  loading from the browser's cache.  I wasn't able to get these to work  correctly for me.&lt;/li&gt;&lt;/ul&gt;So after much effort trying different ways to do this, I went with this rather simple solution:&lt;br /&gt;&lt;br /&gt;When we register the startup script with the alert, immediately follow the alert statement with one which will refresh the page.  This ensures that the startup script is removed from the page as soon as the OK is clicked, and if the user returns to the page the pop up does not reappear.&lt;br /&gt;&lt;br /&gt;Here's a code sample of the script injected with Page.RegisterStartupScript:&lt;br /&gt;&lt;pre class="brush: jscript"&gt;&lt;br /&gt;alert(\"Error with Data\");&lt;br /&gt;__doPostBack('__Page', 'EmptyPostback');&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Originally I was using "window.location = PageName.aspx" instead of "__doPostBack" to refresh my page without the popup, but that caused some ViewState that I needed to be lost.  If you are developing in something other than ASP.Net then window.location may be better for you.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8567593552832750240-5333956807844340093?l=beakdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beakdev.blogspot.com/feeds/5333956807844340093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://beakdev.blogspot.com/2010/11/javascript-popup-appears-again-when.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/5333956807844340093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/5333956807844340093'/><link rel='alternate' type='text/html' href='http://beakdev.blogspot.com/2010/11/javascript-popup-appears-again-when.html' title='Javascript popup appears again when back button pressed'/><author><name>Chris Thomson</name><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-8567593552832750240.post-4849297692591305467</id><published>2010-05-21T13:34:00.003-04:00</published><updated>2010-05-21T13:52:05.941-04:00</updated><title type='text'>Recursive Timers Not Firing</title><content type='html'>Wasted a good while today trying to find out why some Timers I had set up kept stopping firing.  Here's the scenario: I have a windows service that does 2 things.&lt;br /&gt;1) Generate Alerts: Periodically generate a batch of alert emails to send to all users of a system reminding them of pending tasks they have assigned to them.&lt;br /&gt;2) Send Emails: For all emails in a database table, send them.&lt;br /&gt;&lt;br /&gt;Generate Alerts parses a cron format string to determine how often to run.  Send Emails has an interval in milliseconds.  One important point here is that I don't want these tasks to run every X seconds.  I want them to run after X seconds and then again X seconds after the previous run has completed.  Hence I don't want to use a Timer in the standard way as one execution could begin while another is still in progress.&lt;br /&gt;&lt;br /&gt;For this reason, in each case I create a timer to do my work, and then at the end of the timer I create another timer.  Note these are the Timers from System.Threading and are configured to run only once, not at every tick). Here's an example:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp"&gt;&lt;br /&gt;public void StartEmailSender(int waitTime, int retryAttempts)&lt;br /&gt;        {&lt;br /&gt;            log.Debug("Starting EmailSender");&lt;br /&gt;            WaitTime = new TimeSpan(0, 0, 0, 0, waitTime);&lt;br /&gt;            RetryAttempts = retryAttempts;&lt;br /&gt;&lt;br /&gt;            //Set the SendQueuedEmails method to run after the elapsed time.&lt;br /&gt;            emailSenderTimer = new Timer(delegate(object s)&lt;br /&gt;            {&lt;br /&gt;                SendQueuedEmails();&lt;br /&gt;            }&lt;br /&gt;                      , null, WaitTime, new TimeSpan(-1));&lt;br /&gt;            log.Debug("EmailSender Started");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;public void SendQueuedEmails()&lt;br /&gt;        {&lt;br /&gt;            log.Debug("Entering SendQueuedEmails method");&lt;br /&gt;           &lt;br /&gt;            //Code to send emails goes here&lt;br /&gt;&lt;br /&gt;            //Create a new timer to run this method again after the elapsed time.&lt;br /&gt;            emailSenderTimer = new Timer(delegate(object s)&lt;br /&gt;            {&lt;br /&gt;                SendQueuedEmails();&lt;br /&gt;            }&lt;br /&gt;                      , null, WaitTime, new TimeSpan(-1));&lt;br /&gt;&lt;br /&gt;            log.Debug("Exiting SendQueuedEmails method");           &lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The original problem I was having is that the timer would run X number of times and then stop.  Or one of the 2 timers would continue for longer than the other but then eventually stop.  I discovered the reason was that my Timers were being Garbage Collected.&lt;br /&gt;&lt;br /&gt;The above code is the working version.  In my previous version which did not work I was not assigning the output of "new Timer(delegate(object s)" to anything.  Now it gets set to a private class member.  This ensures that there is always a reference to the current Timer so long as the class has not been disposed.  I ensure the class is not disposed by again having a private class member in the service's main class which I initialise in the OnStart method.  Hence the class is not disposed until the service is stopped and hence there is always a reference to the current Timer which is waiting to execute, and only the ones which have already completed get disposed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8567593552832750240-4849297692591305467?l=beakdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beakdev.blogspot.com/feeds/4849297692591305467/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://beakdev.blogspot.com/2010/05/recursive-timers-not-firing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/4849297692591305467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/4849297692591305467'/><link rel='alternate' type='text/html' href='http://beakdev.blogspot.com/2010/05/recursive-timers-not-firing.html' title='Recursive Timers Not Firing'/><author><name>Chris Thomson</name><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-8567593552832750240.post-7851556012917289927</id><published>2010-05-05T10:44:00.002-04:00</published><updated>2010-05-05T10:53:51.345-04:00</updated><title type='text'>Using Refresh Files with WebSite Projects to include DLLs</title><content type='html'>Recently I had a problem whereby my WebSite project (Not WebApplication project) in Visual Studio was missing some DLLs.  These are pre-built DLLs that I load from a set location, for example AjaxControlToolkit.dll and log4net.dll.&lt;br /&gt;&lt;br /&gt;On my build server whenever a build was done I needed a way to have these files copied to the BIN directory of my website.  In a WebApplication or other project these references are specified in the project file (Project.csproj for example), but we don't have a project file for a WebSite project.  The WebSite is just a directory of files and any "project" references are included in the Solution file.&lt;br /&gt;&lt;br /&gt;The way Visual Studio allows us to include DLL files which are not covered by the project references is with the use of a Refresh file.  So for example if I want to include C:\DLLs\AjaxControlToolkit.dll in my WebSite I add it with Add Reference -&gt; Browser -&gt; Choose the file.  Visual Studio then puts a file called AjaxControlToolkit.dll.refresh in my bin directory.  The presence of this file cause the AjaxControlToolkit.dll to be copied from C:\DLLs\ to the BIN directory of my WebSite each time I build it.&lt;br /&gt;&lt;br /&gt;Normally we don't check things in the BIN directory into source control, but Refresh files are the exception.  I added my Refresh file in the BIN directory to CVS and when my Build Server did a check out it got the Refresh file, causing the build to copy the DLL into the BIN directory for my built website.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8567593552832750240-7851556012917289927?l=beakdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beakdev.blogspot.com/feeds/7851556012917289927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://beakdev.blogspot.com/2010/05/using-refresh-files-with-website.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/7851556012917289927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/7851556012917289927'/><link rel='alternate' type='text/html' href='http://beakdev.blogspot.com/2010/05/using-refresh-files-with-website.html' title='Using Refresh Files with WebSite Projects to include DLLs'/><author><name>Chris Thomson</name><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-8567593552832750240.post-4410405227558198666</id><published>2010-05-03T10:53:00.008-04:00</published><updated>2010-05-05T11:38:10.130-04:00</updated><title type='text'>Query String Encoding Hassles with &amp; in ASP.Net</title><content type='html'>&lt;span style="font-family:arial;"&gt;Today I encountered an odd problem which I remember having years ago but had no memory of how to solve it....&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;So I'm creating a URL with a query string which will appear in a web page:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: csharp"&gt;thumbnailImage.ImageUrl =  "~/UserControls/ImageHandler.ashx?" + "id=" + productImages[0].UId + "&amp;amp;thumb=true&amp;amp;size=100"&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family:arial;"&gt;Now when this appears in the web page, it seems that all of the "&amp;amp;" symbols, which represent the delimiter between parameters, get changed to "&amp;amp;"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The problem with this is that when the page that is linked to resolves the query parameters I get:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: csharp"&gt;&lt;br /&gt;context.Request.Params["thumb"]&lt;br /&gt;null&lt;br /&gt;&lt;/pre&gt;&lt;pre class="brush: csharp"&gt;&lt;br /&gt;context.Request.Params["amp;thumb"]&lt;br /&gt;"true"&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family:arial;"&gt;The first thing I tried was to use Server.URLEncode.  This changes the "&amp;amp;" symbols to "%26".  This in itself is no use, but when used with Server.URLDecode means we end up with the correct query string.  It still gives us a problem however because we can no longer use the string index for context.Request.Params.  We'd have to manually parse the string output of URLDecode to find the required parameter.  Not difficult I know, but a little untidy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The solution I eventually found was to use:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: csharp"&gt;thumbnailImage.ImageUrl = String.Format("~/UserControls/ImageHandler.ashx?" + "id=" + productImages[0].UId + "&amp;amp;thumb=true&amp;amp;size=100");&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family:arial;"&gt;It appears that the String.Format causes the "&amp;amp;" symbols not to be changed to "&amp;amp;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;amp;"&lt;br /&gt;&lt;br /&gt;Exactly why that happens I do not know, it seems that the output of String.Format is the same as the original string:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: csharp"&gt;String.Format("~/UserControls/ImageHandler.ashx?" + "id=" + productImages[0].UId + "&amp;amp;thumb=true&amp;amp;size=100").Equals("~/UserControls/ImageHandler.ashx?" + "id=" + productImages[0].UId + "&amp;amp;thumb=true&amp;amp;size=100")&lt;br /&gt;true&lt;/pre&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Strange... but it seems to work.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8567593552832750240-4410405227558198666?l=beakdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beakdev.blogspot.com/feeds/4410405227558198666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://beakdev.blogspot.com/2010/05/query-string-encoding-hassles-with-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/4410405227558198666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8567593552832750240/posts/default/4410405227558198666'/><link rel='alternate' type='text/html' href='http://beakdev.blogspot.com/2010/05/query-string-encoding-hassles-with-in.html' title='Query String Encoding Hassles with &amp;amp; in ASP.Net'/><author><name>Chris Thomson</name><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>
