<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ASP.NET Tutorials &#187; Code snippets</title>
	<atom:link href="http://www.tutorialsasp.net/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tutorialsasp.net</link>
	<description>Get stuff done with ASP.NET</description>
	<lastBuildDate>Tue, 31 Aug 2010 17:23:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Get the IP Address and Referer of a visitor</title>
		<link>http://www.tutorialsasp.net/code-snippets/get-the-ip-address-and-referer-of-a-visitor/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/get-the-ip-address-and-referer-of-a-visitor/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 06:24:11 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[IP Address]]></category>
		<category><![CDATA[referer]]></category>

		<guid isPermaLink="false">http://www.tutorialsasp.net/?p=243</guid>
		<description><![CDATA[Here is the code snippet to obtain the IP Address and Referer of a visitor to your website Dim IPAddress=Request.ServerVariables("REMOTE_ADDR") Dim Referer=Request.ServerVariables("HTTP_REFERER") Check a demo here Check my IP]]></description>
			<content:encoded><![CDATA[<p>Here is the code snippet to obtain the IP Address and Referer of a visitor to your website<br />
<code><br />
Dim IPAddress=Request.ServerVariables("REMOTE_ADDR")<br />
Dim Referer=Request.ServerVariables("HTTP_REFERER")<br />
</code></p>
<p>Check a demo here</p>
<p><a rel="nofollow,noindex" href="http://www.TickleJokes.com/IPAddress.aspx" target="_self">Check my IP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/get-the-ip-address-and-referer-of-a-visitor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replace &#8220;\n&#8221; with &#8220;&lt;BR\&gt;&#8221;</title>
		<link>http://www.tutorialsasp.net/code-snippets/replace-line-breaks-wit-br/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/replace-line-breaks-wit-br/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 18:07:40 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[\n to]]></category>

		<guid isPermaLink="false">http://www.tutorialsasp.net/?p=212</guid>
		<description><![CDATA[There are lot of times we accept user input in a textarea or a multiline textbox and save it to a database. But while displaying the data from the database, you will find that the line breaks are not displayed properly, infact there will be no line breaks. We will need to convert all the [...]]]></description>
			<content:encoded><![CDATA[<p>There are lot of times we accept user input in a textarea or a multiline textbox and save it to a database. But while displaying the data from the database, you will find that the line breaks are not displayed properly, infact there will be no line breaks. We will need to convert all the new line characters (&#8220;\n&#8221; character) to &#8220;&lt;BR/&gt;&#8221; so that they are properly rendered in the browser. There seems to be quite a few ways to do it but the simplest method which always worked for me is as follows. Just pass the string to the the function and it will format the string properly so that the new line characters  are replaced with &#8220;&lt;Br/&gt;&#8221; tags<br />
<code><br />
Public Shared Function ConvertToBR(ByVal InputString As String) As String<br />
Dim Pattern As String = "\n"<br />
Dim Rgx As New Regex(Pattern)<br />
Dim OutputString As String=Rgx.Replace(InputString, "&lt;br/&gt;")<br />
Return OutputString<br />
End Function<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/replace-line-breaks-wit-br/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Efficient Search Engine Friendly Gridview Paging control</title>
		<link>http://www.tutorialsasp.net/code-snippets/efficient-search-engine-friendly-gridview-paging-control/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/efficient-search-engine-friendly-gridview-paging-control/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 08:51:26 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[Gridview]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.tutorialsasp.net/?p=208</guid>
		<description><![CDATA[The Gridview Control in ASP.NET has built in paging support. But here are a few disadvantages of using the built in paging It fetches all the records from the database even when we need only 10 records per page. This is quite inefficient when your tables have thousands of records The paging controls uses javascript [...]]]></description>
			<content:encoded><![CDATA[<p>The Gridview Control in ASP.NET has built in paging support.  But here are a few disadvantages of using the built in paging</p>
<ul>
<li>It fetches all the records from the database even when we need only 10 records per page. This is quite inefficient when your tables have thousands of records</li>
<li>The paging controls uses javascript which makes the pages inaccessible to search engine.</li>
</ul>
<p>I looked around the net for solutions to these problems. There were a few solutions and some of them even costs upwards of $100 but the best I found was a free paging control by Bidel Akbari at <a title="Paging control" href="http://www.codeproject.com/KB/custom-controls/ASPNETPagerControl.aspx" target="_blank">codeproject</a></p>
<p>Here are the main features of his paging control</p>
<ul>
<li>Very easy to install and use.</li>
<li>Uses server side  paging so that only the required few rows are returned from the database</li>
<li> Search engine friendly paging.  The first version was supposed to use query strings for paging which is the way paging should work. However in the latest version 2.8 , it uses javascript for paging and a hidden div with hyperinks so that search engines can find the inner pages.</li>
<li>You can use the paging control with the Repeater and Datalist controls</li>
<li>There are a variety of properties to change the appearance of the control. He has also made two slick skins for the control</li>
</ul>
<p>Overall a great and extremely useful control . You can see a demo of the control here in my site <a href="http://www.freedownloadablefonts.net/ListFonts.aspx?alphabet=A" target="_self">freedownloadablefonts.net</a> .  You can find more info and download the control <a href="http://www.codeproject.com/KB/custom-controls/ASPNETPagerControl.aspx" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/efficient-search-engine-friendly-gridview-paging-control/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to access a control in the masterpage ?</title>
		<link>http://www.tutorialsasp.net/code-snippets/how-to-access-a-control-in-the-masterpage/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/how-to-access-a-control-in-the-masterpage/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 20:11:44 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[Access control in masterpage]]></category>

		<guid isPermaLink="false">http://tutorialsasp.net/?p=47</guid>
		<description><![CDATA[Suppose you have a label control name lblMessage in your masterpage and you want to access the label control from one of your pages, you can do so using the following code Ctype( Page.Master.FindControl("lblMessage"),Label).Text = "Hello"]]></description>
			<content:encoded><![CDATA[<p>Suppose you have a label control name  lblMessage in your masterpage and you want to access the label control from one of your pages, you can do so using the following code</p>
<div style="clear:both"></div>
<p><code><br />
Ctype( Page.Master.FindControl("lblMessage"),Label).Text = "Hello"<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/how-to-access-a-control-in-the-masterpage/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Insert flash file correcty in ASP.NET masterpage</title>
		<link>http://www.tutorialsasp.net/code-snippets/insert-flash-file-correcty-in-aspnet-masterpage/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/insert-flash-file-correcty-in-aspnet-masterpage/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 19:58:03 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[Flash file in masterpage]]></category>

		<guid isPermaLink="false">http://tutorialsasp.net/?p=44</guid>
		<description><![CDATA[Many people have problems inserting flash files in masterpages . The following code is the correct way of inserting flash file in a mastepage . It will work in all situations &#60;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase= "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="663" height="105" title="Serious Reading...."&#62; &#60;param name="movie" value='&#60;%= Request.ApplicationPath + "main_anim.swf" %&#62;' &#60;param name="quality" value="high" /&#62; &#60;embed src='&#60;%= Request.ApplicationPath + "main_anim.swf" [...]]]></description>
			<content:encoded><![CDATA[<p>Many people have problems inserting <strong>flash files in masterpages</strong> . The following code is the correct way of inserting flash file in a mastepage . It will work in all situations</p>
<div style="clear:both"></div>
<p><code><br />
&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase= "<a href="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0</a>" width="663" height="105" title="Serious Reading...."&gt;<br />
&lt;param name="movie" value='&lt;%= Request.ApplicationPath + "main_anim.swf" %&gt;'<br />
&lt;param name="quality" value="high" /&gt;<br />
&lt;embed src='&lt;%= Request.ApplicationPath + "main_anim.swf" %&gt;' pluginspage="<a href="http://www.macromedia.com/go/getflashplayer">http://www.macromedia.com/go/getflashplayer</a>" type="application/x-shockwave-flash" width="663" height="105"&gt;&lt;/embed&gt;<br />
&lt;/object&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/insert-flash-file-correcty-in-aspnet-masterpage/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Format dates in a Gridview column</title>
		<link>http://www.tutorialsasp.net/code-snippets/format-dates-in-a-gridview-column/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/format-dates-in-a-gridview-column/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 19:01:05 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[Format dates]]></category>
		<category><![CDATA[Gridview]]></category>

		<guid isPermaLink="false">http://tutorialsasp.net/?p=12</guid>
		<description><![CDATA[To format a gridview column to display dates properly , two properties needs to be changed, the DateFormatString property and the HTML encode property. After setting the DateFormatString the HTMLEncode property should be set to false. For Example : &#60;asp:BoundField DataField="RegistrationDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date" HtmlEncode="False" SortExpression="RegistrationDate" /&#62;]]></description>
			<content:encoded><![CDATA[<p>To format a gridview column to display dates properly , two properties needs to be changed, the DateFormatString property and the HTML encode property. After setting the DateFormatString the HTMLEncode property should be set to false. For Example :<br />
<code><br />
&lt;asp:BoundField DataField="RegistrationDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date"<br />
HtmlEncode="False" SortExpression="RegistrationDate" /&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/format-dates-in-a-gridview-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable or disable the delete link in the GridView according to the role of the logged in user</title>
		<link>http://www.tutorialsasp.net/code-snippets/enable-or-disable-the-delete-link-in-the-gridview-according-to-the-role-of-the-logged-in-user/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/enable-or-disable-the-delete-link-in-the-gridview-according-to-the-role-of-the-logged-in-user/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 18:58:56 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[Gridview]]></category>

		<guid isPermaLink="false">http://tutorialsasp.net/?p=11</guid>
		<description><![CDATA[In some scenarios you may only want users of a particular role to delete records from the GridView. So you need a mechanism to disable/hide the delete link in the gridview based on roles. The code below will enable the delete link only for &#8220;Admin&#8221; roles and disable it for the rest. Protected Sub gridView1_RowDataBound(ByVal [...]]]></description>
			<content:encoded><![CDATA[<p>In some scenarios you may only want users of a particular role to delete records from the GridView. So you need a mechanism to disable/hide the delete link in the gridview based on roles.  The code below  will  enable the delete link only for &#8220;Admin&#8221; roles and disable it for the rest.</p>
<p><code><br />
Protected Sub gridView1_RowDataBound(ByVal sender As Object, ByVal e As system.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound<br />
If e.Row.RowType = DataControlRowType.DataRow Then<br />
   If User.IsInRole("Admin") Then<br />
      Dim DeleteLink As LinkButton = CType(e.Row.FindControl("HyperLinkDelete"), LinkButton)<br />
      DeleteLink.Enabled = true<br />
   else<br />
        DeleteLink.Enabled = True<br />
   End If<br />
End If<br />
End Sub<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/enable-or-disable-the-delete-link-in-the-gridview-according-to-the-role-of-the-logged-in-user/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How do I reference a server control in javascript?</title>
		<link>http://www.tutorialsasp.net/code-snippets/how-do-i-reference-a-server-control-in-javascript/</link>
		<comments>http://www.tutorialsasp.net/code-snippets/how-do-i-reference-a-server-control-in-javascript/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 18:47:47 +0000</pubDate>
		<dc:creator>Vihutuo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[ASP.NET javascript control]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tutorialsasp.net/?p=6</guid>
		<description><![CDATA[&#60;%=ServerControlID.ClientID%&#62; Yes that&#8217;s all you need . For Example suppose you have a asp.net textbox server control whose ID is &#8220;Textbox1&#8243; . In your javascript code to get the value of the control you will use something like this var myValue= document.getElementById('&#60;%=TextBox1.ClientID%&#62;').value;]]></description>
			<content:encoded><![CDATA[<p><code>&lt;%=ServerControlID.ClientID%&gt;</code></p>
<p>Yes that&#8217;s all you need . For Example suppose you have a asp.net textbox  server control whose ID is &#8220;Textbox1&#8243; . In your javascript code to get the value of the control you will use something like this</p>
<div style="clear:both"></div>
<p><code>var myValue= document.getElementById('&lt;%=TextBox1.ClientID%&gt;').value;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialsasp.net/code-snippets/how-do-i-reference-a-server-control-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

