<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Tips Tricks and Frustrating Errors</title>
        <link>http://geekswithblogs.net/StealThisCode/category/2685.aspx</link>
        <description>Tips Tricks and Frustrating Errors</description>
        <language>en-US</language>
        <copyright>Jeff Tolle</copyright>
        <managingEditor>jeff.tolle@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>How to make your ASP.Net label multiline (how to wrap text in your label)</title>
            <link>http://geekswithblogs.net/StealThisCode/archive/2006/03/21/WrapLabels.aspx</link>
            <description>First off, sorry for the absence.  Things got a little busy in life as well as work.  Not to mention having to get up to speed on 2.0 in a big hurry.  All good things, but it left less time for fun stuff.&lt;br/&gt;&lt;br/&gt;

With that said, I want to offer a little tip to help with formatting your ASP.Net pages.  Getting a label to be multiline within a set width.  Now many of you know this trick, but I always have to re-remember the trick every time I need it, so this post can be a reference for you as well.&lt;br/&gt;&lt;br/&gt;

The trick is actually this - Don't use a label.  Use a textbox instead.  Since all the controls inherit from the same base class, the text box and the label are very similar anyway.  But only the textbox has the multiline capability.&lt;br/&gt;&lt;br/&gt;

Once you have the textbox on your page the trick is to make it look like a label for the end user.  To do this you need to set the following properties (This is the part I can never remember):&lt;br/&gt;&lt;br/&gt;

Wrap = true; (obviously)&lt;br/&gt;
rows = {some number greater than 0} (I use the rows property rather than the height property as it tends to be earier to get the formatting right)&lt;br/&gt;
ReadOnly = true (makes sense, right)&lt;br/&gt;
TextMode = multiline (or there no real reason to wrap the text...)&lt;br/&gt;
BorderStyle = None &lt;br/&gt;
BorderWidth = 0&lt;br/&gt;&lt;br/&gt;

Those last two are actually VERY important, and here is why.  They get rid of that pesky border that you see around text boxes.  That border is a common visual signal to the end user that says "ENTER INFO HERE!".  If you leave the border up expect a lot of phone calls from folks saying "The web page is broken.  It won't let me enter text."&lt;br/&gt;&lt;br/&gt;

So use this in good faith.  More controls soon.  Even my first 2.0 controls.
&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=72888"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=72888" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/StealThisCode/aggbug/72888.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Tolle</dc:creator>
            <guid>http://geekswithblogs.net/StealThisCode/archive/2006/03/21/WrapLabels.aspx</guid>
            <pubDate>Tue, 21 Mar 2006 18:04:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/StealThisCode/comments/72888.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/StealThisCode/archive/2006/03/21/WrapLabels.aspx#feedback</comments>
            <slash:comments>59</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/StealThisCode/comments/commentRss/72888.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/StealThisCode/services/trackbacks/72888.aspx</trackback:ping>
        </item>
        <item>
            <title>ASP.Net 2.0 error 'The Sitemappath 'Web.sitemap' cannot be found'</title>
            <link>http://geekswithblogs.net/StealThisCode/archive/2005/11/16/60293.aspx</link>
            <description>&lt;P&gt;This was a frutrating one, and since 2.0 is so new, I couldn't find anything about this on the web.&amp;nbsp; But eventually, I figured it out...&lt;br/&gt;&lt;br/&gt;&lt;/P&gt;
&lt;P&gt;The answer is that you can not specify the web.sitemap in the data source controls.&amp;nbsp; It is actually the default, and ASP.Net 2.0 selects this automaically.&amp;nbsp; If you try to tell it specifically to look for the default it has an stroke.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=60293"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=60293" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/StealThisCode/aggbug/60293.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Tolle</dc:creator>
            <guid>http://geekswithblogs.net/StealThisCode/archive/2005/11/16/60293.aspx</guid>
            <pubDate>Wed, 16 Nov 2005 19:53:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/StealThisCode/comments/60293.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/StealThisCode/archive/2005/11/16/60293.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/StealThisCode/comments/commentRss/60293.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/StealThisCode/services/trackbacks/60293.aspx</trackback:ping>
        </item>
        <item>
            <title>How to scrape a website without being stumped by 999 errors</title>
            <link>http://geekswithblogs.net/StealThisCode/archive/2005/10/17/57209.aspx</link>
            <description>Web site scraping is a great tool, and it is so easy in .Net.  But there are some snags, especially if you are trying to build a robust system that can run unattended.  One of these problems are web errors like '999 web site temporarily unavailable.'  .Net views these errors as fatal and boom you are out of the program.  Now you can catch them then recall the mentod, but this recursive action can eat up memory very quickly.  There is however another way:&lt;br/&gt;&lt;br/&gt;

public static string ScrapeURL (string URL) {&lt;br/&gt;
			HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL); &lt;br/&gt;
			HttpStatusCode code = new HttpStatusCode(); &lt;br/&gt;
			HttpWebResponse resp = null; &lt;br/&gt;
			&lt;br/&gt;
			try { &lt;br/&gt;
				resp = (HttpWebResponse)req.GetResponse(); &lt;br/&gt;
				code = resp.StatusCode; &lt;br/&gt;
			} catch(WebException err) { &lt;br/&gt;
				return null;&lt;br/&gt;
			}&lt;br/&gt;
&lt;br/&gt;
			string strResult;&lt;br/&gt;
&lt;br/&gt;
			using (StreamReader sr =&lt;br/&gt;
						 new StreamReader(resp.GetResponseStream())) {&lt;br/&gt;
				strResult = sr.ReadToEnd();&lt;br/&gt;
				// Close and clean up the StreamReader&lt;br/&gt;
				sr.Close();&lt;br/&gt;
			}&lt;br/&gt;
			return strResult; &lt;br/&gt;
		}&lt;br/&gt;&lt;br/&gt;

Then all you have to do is call this procedure in a do..while (response !=null) loop and away you go.  Notice that you avoid stacking up multiple calls because all we are doing here is ignoring the WebErrors.&lt;br/&gt;&lt;br/&gt;

You can also get more specific and use the code = resp.StatusCode in a case satatement to different things based on the specific HttpWebError.  (ie you may want to react to a 404 error differently than you do for a 999 error.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=57209"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=57209" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/StealThisCode/aggbug/57209.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Tolle</dc:creator>
            <guid>http://geekswithblogs.net/StealThisCode/archive/2005/10/17/57209.aspx</guid>
            <pubDate>Mon, 17 Oct 2005 23:37:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/StealThisCode/comments/57209.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/StealThisCode/archive/2005/10/17/57209.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/StealThisCode/comments/commentRss/57209.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/StealThisCode/services/trackbacks/57209.aspx</trackback:ping>
        </item>
        <item>
            <title>Response.Redirect not working (I'm looking at you SmartNavigation)</title>
            <link>http://geekswithblogs.net/StealThisCode/archive/2005/09/15/53918.aspx</link>
            <description>Whew.  It has been a crazy two weeks on this project, and it all culminated with a nasty error where Response.Redirect was on the fritz.  This one tore me up before I was able to figure out what was going wrong.
&lt;br/&gt;&lt;br/&gt;
Basically I was doing a Response.Redirect on a page, and in Dev and Test it worked like a charm.  Even after I moved it to production it worked for a while.  But then the horror occurred.  The response redirect suddenly would simply post back to the same page - no redirect at all.
&lt;br/&gt;&lt;br/&gt;
I was able to narrow it down to the response.redirect fairly quickly, but I assumed it wasn't playing nice with some server setting in Prod that wasn't switched on in Dev or Test.
&lt;br/&gt;&lt;br/&gt;
Well - I am not entirely convinced that some switch in IIS didn't get flipped, but quite frankly going down that rabbit hole wasn't getting me anywhere, and the client was waiting.
&lt;br/&gt;&lt;br/&gt;
So I looked at all the opages to see how this one differed.  Turns out this page was the only one with SmartNavigation turned on.  So I set SmartNavigation to false, and voila.
&lt;br/&gt;&lt;br/&gt;
Hope this tip helps some frustrated soul out!
&lt;br/&gt;&lt;br/&gt;
EDIT: I have learned more about this error.  See &lt;a href ="http://geekswithblogs.net/stealthiscode/archive/2006/05/16/78566.aspx"&gt;here&lt;/a&gt; for details.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=53918"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=53918" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/StealThisCode/aggbug/53918.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Tolle</dc:creator>
            <guid>http://geekswithblogs.net/StealThisCode/archive/2005/09/15/53918.aspx</guid>
            <pubDate>Thu, 15 Sep 2005 18:19:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/StealThisCode/comments/53918.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/StealThisCode/archive/2005/09/15/53918.aspx#feedback</comments>
            <slash:comments>26</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/StealThisCode/comments/commentRss/53918.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/StealThisCode/services/trackbacks/53918.aspx</trackback:ping>
        </item>
    </channel>
</rss>