<?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-7926983505765515035</id><updated>2011-11-28T05:09:28.387+05:30</updated><category term='Mobile Controls - Displaying ObjectList'/><category term='web.config File - Custom Application Settings'/><category term='Connecting to MS Access DB'/><category term='web.config - Custom Settings'/><category term='State Management'/><category term='Custom Conrols'/><category term='Output Caching by HTTP Headers'/><category term='ASP.NET Pop up window'/><category term='Cache Dependency'/><category term='Forms Authentication'/><category term='Creating Templated Control'/><category term='Connecting to SQL Server'/><category term='Connecting to Oracle'/><category term='Mobile Controls - Customizing Output'/><category term='Mobile Controls -  Automatic Paging'/><category term='Connecting to MySQL DB'/><category term='CallBack when a Cached'/><category term='Security in ASP.NET'/><category term='Output Caching'/><category term='Handling Page Level Errors in ASP.NET'/><category term='Catching Exceptions in ASP.NET'/><category term='Adding Controls ASP.NET form'/><category term='Application Error Handling'/><category term='Late-Bound User Control'/><category term='Application Debugging'/><category term='Mobile Controls - Web Form'/><category term='Security - Logout Form'/><category term='ASP.NET Client Side Events with JS'/><category term='Caching - Retrieving Data'/><category term='ASP.NET Stateful Page Member'/><category term='Sharing User Controls'/><category term='Output Caching by Browser'/><category term='IIS Authentication'/><category term='Caching'/><category term='Loading User Controls ASP.NET'/><category term='Tracing'/><category term='Per-Request Caching'/><category term='Security - Custom Auth'/><category term='Displaying an Image from SQL Server'/><category term='Raising Exceptions in ASP.NET'/><category term='Setting Control Focus'/><category term='Data Access'/><category term='Creting Data-bound Conrol'/><category term='Connecting to ODBC DB'/><category term='Composite Control'/><category term='Web Controls'/><category term='Sessions'/><category term='Security - Login Form'/><category term='ASP.NET information Passing'/><category term='ViewState'/><category term='Cookies'/><category term='ASP.NET Redirecting User'/><category term='Uploading a File'/><category term='Caching -  VaryByControl'/><category term='Rending Image in ASP.NET'/><category term='Page Level Tracing in ASP.NET'/><category term='cache - inserting data'/><category term='Mobile Controls - Navigation'/><category term='Session Object'/><title type='text'>ASP.NET Slackers All concepts covered</title><subtitle type='html'>ASP.NET programming best practices from basics to advanced level includes Forms, Controls, Caching, State Management, Security, Error Handling, Debugging, Operations with ADO.NET, Classes, Manipulating Strings, Collections, Web Services, LDAP/ADSI Directory Services, Threading, Remoting, Reflection, and CodeDOM.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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>100</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7926983505765515035.post-7094658207959454752</id><published>2008-10-20T17:38:00.001+05:30</published><updated>2008-10-20T17:38:33.429+05:30</updated><title type='text'>Change the Permissions Given to ASP.NET Code</title><content type='html'>&lt;p class="first-para"&gt;ASP.NET code doesn't run under the IIS authenticated user or the anonymous IUSR_[ServerName] account. Part of the reason is that this account usually won't have sufficient privileges for ASP.NET code, which needs to be able to create and delete temporary files to manage the Web page compilation process.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;By default, ASP.NET pages run using the local ASPNET account, which has a carefully limited set of privileges. If you need your ASP.NET code to perform something that is not allowed by default for the local account (writing to the server hard drive or the event log, for example), you can explicitly grant these rights to the ASPNET process. You can also change the setting by editing the machine.config file and modifying the &amp;lt;&lt;em&gt;processModel&lt;/em&gt;&amp;gt; tag. You can set the &lt;em&gt;userName&lt;/em&gt; and &lt;em&gt;password&lt;/em&gt; attributes to any arbitrary user, or you can make use of the built-in local ASPNET process (set &lt;em&gt;userName&lt;/em&gt; to Machine and &lt;em&gt;password&lt;/em&gt; to AutoGenerate) or local system account (set &lt;em&gt;userName&lt;/em&gt; to System and &lt;em&gt;password&lt;/em&gt; to AutoGenerate). Because the local system has full rights to the computer, using this account is never recommended except for testing purposes. The ASP.NET account settings are global, and all Web applications will share the account that you specify.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;You can also change the account used to execute certain applications or specific code by using impersonation. For example, to configure a single Web application to run under a different user account, add the &amp;lt;&lt;em&gt;identity&lt;/em&gt;&amp;gt; tag to the Web.config file, as shown here:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;  &amp;lt;system.web&amp;gt;&lt;br /&gt;    &amp;lt;!-- Other settings omitted. --&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;&lt;strong&gt;identity impersonate="true" name="domain\user" password="pwd"/&lt;/strong&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="para"&gt;You can also instruct the Web application to use the identity that was authenticated by IIS, which will be the anonymous IUSR_[ServerName] account if you aren't using Windows authentication. Simply add the &amp;lt;&lt;em&gt;identity&lt;/em&gt;&amp;gt; tag without supplying any user credentials:&lt;/p&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;identity impersonate="true"/&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p class="para"&gt;Remember, for this type of impersonation to work, the user account will require read/write access to the Temporary ASP.NET Files directory where the compiled ASP.NET files are stored. This directory is located under the path C:\[WindowsDirectory]\Microsoft.NET\Framework\[version]\Temporary ASP.NET Files.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;Finally, you can also use impersonation programmatically, to change the account used to execute a particular section of code. The following code snippet shows a brief example that works in conjunction with Windows authentication. Provided IIS has authenticated the user, that user identity will be assumed when the &lt;em&gt;WindowsIdentity.Impersonate&lt;/em&gt; method is used. To use this code, you must import the &lt;em&gt;System.Security.Principal&lt;/em&gt; namespace.&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;if (User.GetType() == typeof(WindowsPrincipal)) {&lt;br /&gt;&lt;br /&gt;    WindowsIdentity id = (WindowsIdentity)User.Identity;&lt;br /&gt;    WindowsImpersonationContext impersonate = id.Impersonate();&lt;br /&gt;&lt;br /&gt;    // (Now perform tasks under the impersonated ID.)&lt;br /&gt;&lt;br /&gt;    // Revert to the original ID as shown below.&lt;br /&gt;    impersonate.Undo();&lt;br /&gt;} else {&lt;br /&gt;&lt;br /&gt;    // User is not Windows authenticated.&lt;br /&gt;    // Throw an error to or take other steps.&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7094658207959454752?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7094658207959454752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7094658207959454752' title='41 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7094658207959454752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7094658207959454752'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/change-permissions-given-to-aspnet-code.html' title='Change the Permissions Given to ASP.NET Code'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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>41</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7926983505765515035.post-4303746520576643864</id><published>2008-10-20T17:36:00.001+05:30</published><updated>2008-10-20T17:36:26.994+05:30</updated><title type='text'>ASP.Net Enabling Web Site Debugging</title><content type='html'>&lt;p class="first-para"&gt;The "unable to start debugging" error signals that Visual Studio .NET was able to compile the Web application but can't execute it in debug mode. Unfortunately, this problem can arise for different reasons, including the following:&lt;/p&gt;&lt;br /&gt;&lt;ul class="itemizedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;IIS, the Windows component that hosts Web applications, is not installed or is installed incorrectly.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;The user running Visual Studio .NET is not a member of the Debugger Users group for the Web server.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;The user running Visual Studio .NET doesn't have permissions to debug the ASP.NET process. For example, if the ASP.NET process is running under the local system account, the user must have Administrator privileges to debug it.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;The Web server is running a version of Windows that doesn't support debugging, such as Microsoft Windows NT and Windows XP Home Edition. (Windows 2000, Windows XP Professional, Windows XP Server, and Windows Server 2003 all support debugging.)&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;The Web application doesn't have a Web.config file, or the Web.config file doesn't enable debugging.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;You're running Visual Studio .NET, and you haven't enabled Integrated Windows authentication for the virtual directory.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p class="para"&gt;The first step that you should take when diagnosing why you can't debug a Web application is to check that IIS is installed on the Web server. To do so, open &lt;em&gt;&lt;a href="http://localhost/localstart.asp" class="url" target="_top"&gt;http://localhost/localstart.asp&lt;/a&gt;&lt;/em&gt; in your browser. (localhost is an alias for the current computer.) If the test page doesn't appear, IIS is not installed or is not enabled. You can also attempt to start your Web application without debugging by selecting Debug | Start Without Debugging from the Visual Studio .NET main menu. If this test is successful, IIS is correctly installed.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;If you installed IIS after you installed Visual Studio .NET or the .NET Framework, you might need to "repair" the .NET Framework by using the original setup CD or DVD. To start this process, type the following command at the command line (or in the Run window), using the Visual Studio .NET DVD. (It's split into two lines below because of page constraints, but it should be entered on a single line.)&lt;/p&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;DVD Drive&amp;gt;:\wcu\dotNetFramework\dotnetfx.exe /t:c:\temp &lt;br /&gt;  /c:"msiexec.exe /fvecms c:\temp\netfx.msi"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p class="para"&gt;If you're using the CD version of Visual Studio .NET, use the following command line with the Windows Component Update disc:&lt;/p&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;CD Drive&amp;gt;:\dotNetFramework\dotnetfx.exe /t:c:\temp &lt;br /&gt;  /c:"msiexec.exe /fvecms c:\temp\netfx.msi"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p class="para"&gt;If IIS is properly installed, the next step is to validate your Web application's Web.config file. The Web.config file should follow the structure shown here:&lt;/p&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;   &amp;lt;system.web&amp;gt;&lt;br /&gt;      &amp;lt;&lt;strong&gt;compilation defaultLanguage="c#"&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;debug="true" &lt;/strong&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;!-- Other settings omitted. --&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p class="para"&gt;By default, Visual Studio .NET adds the &lt;em&gt;compilation&lt;/em&gt; tag to the automatically generated Web.config file with the &lt;em&gt;debug&lt;/em&gt; attribute set to &lt;em&gt;true&lt;/em&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The next step is to verify the IIS configuration. Problems will occur if you fail to create the required virtual application directory or if you try to run a Web application after you've removed or modified the virtual directory. To correct these problems, modify the virtual directory settings in IIS Manager by selecting Control Panel | Administrative Tools | Internet Information Services from the Start menu. Verify that the virtual application directory exists and that it's configured as a Web application. (You can see virtual directory settings by right- clicking the directory and choosing Properties.) For example, in the screen shot shown in the below figure, the virtual directory exists but is not configured as a Web application. To resolve this problem, you simply need to click the Create button in the Application Settings section.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;&lt;img src="http://img262.imageshack.us/img262/4623/ffpl3.jpg" alt="ff.JPG" height="269" width="296"/&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;One other IIS configuration problem that can occur in Visual Studio .NET is a failure to authenticate. Visual Studio .NET attempts to access the local Web server using Integrated Windows authentication, even if you have anonymous authentication enabled for the virtual directory. This means that your virtual directory must allow both anonymous and Integrated Windows authentication. To allow both authentication methods, follow these steps:&lt;/p&gt;&lt;br /&gt;&lt;ol class="orderedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;In IIS Manager, right-click the virtual directory for your application and choose Properties. (Alternatively, you can configure authentication for all directories if you right-click the Web Sites folder and choose Properties.)&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;Select the Directory Security tab.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;In the Anonymous access and authentication control section, click the Edit button.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;In the Authentication Methods dialog box, under Authenticated access, select Integrated Windows authentication, as shown in below figure.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;Click OK to apply your changes.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://img262.imageshack.us/img262/7673/figzy4.jpg" alt="fig.JPG" height="264" width="227"/&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4303746520576643864?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4303746520576643864/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4303746520576643864' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4303746520576643864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4303746520576643864'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/aspnet-enabling-web-site-debugging.html' title='ASP.Net Enabling Web Site Debugging'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-8566575524259270806</id><published>2008-10-16T13:08:00.001+05:30</published><updated>2008-10-16T13:08:12.369+05:30</updated><title type='text'>ASP.NET Web Service Creation</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;To illustrate creating a Web service, this simple example takes a string and returns a&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;message.To do this, you type in the following code and save it as code01vb.asmx&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;%@ WebService Language="vb" Class="codevb" %&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Imports System.Web.Services&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Imports System.Text&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Class code01vb&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;WebMethod()&amp;gt; _&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Function GreetCustomer(ByVal person as String) As String&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim output As StringBuilder = New StringBuilder()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;output.Append("Welcome to Cook Center Mr/Mrs.")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;output.Append(Person)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;output.Append(" , Hope you are enjoying our examples!!" )&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;GreetCustomer = output.ToString()&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Function&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Class&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Now, you save this file in some Web directory.This is all that is required to create a Web&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;service! To see how it works, open the file in a Web browser. Microsoft provides a default&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;test page feature in the .NET Framework for its Web services. In that page, you will see&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;a &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;GreetCustomer&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;function. Click it, and it will take you to another page.There, you&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;enter some text and press Invoke. A new window opens with the output in XML&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;format.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In this class, you create a Web method called&lt;/font&gt; &lt;font face="Courier" size="1"&gt;GreetCustomer&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. By adding the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;WebMethod()&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute to a method&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;within a .ASMX file, you create a Web service. Here, the &lt;font face="Courier" size="1"&gt;Key&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute is&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;WebMethod&amp;gt;&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This &lt;font face="Courier" size="1"&gt;WebMethod&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute indicates to the .NET Framework that the specified method&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;should be made accessible via standard Internet protocols.These Web service methods&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;should be defined as &lt;font face="Courier" size="1"&gt;public&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, which indicates that they can be accessible from outside&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;parent class.This Web method has various attributes. This example uses the &lt;font face="Courier" size="1"&gt;description&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;attribute.The following properties are defined for the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;WebMethod&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;BufferResponse&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-Specifies whether the response for this Web method should be buffered. By default, it is set to&lt;/font&gt; &lt;font face="Courier" size="1"&gt;True&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;CacheDuration&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-This specifies the number of seconds the Web method response is stored in cache.&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;Description&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-Specifies the user-friendly description of the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;public&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;Web method.&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;EnableSession&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-Specifies whether session state is enabled for the Web method. Default setting is&lt;/font&gt; &lt;font face="Courier" size="1"&gt;false&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;MessageName&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-Specifies an alias name for a Web method.This&lt;/font&gt; &lt;font face="Courier" size="1"&gt;MessageName&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute allows you to provide different names for overloaded methods.&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;TransactionOption&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-Specifies the Enterprise service transaction support for the Web method.&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-8566575524259270806?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/8566575524259270806/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=8566575524259270806' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8566575524259270806'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8566575524259270806'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/aspnet-web-service-creation.html' title='ASP.NET Web Service Creation'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-2911679513104798027</id><published>2008-10-16T13:01:00.001+05:30</published><updated>2008-10-16T13:08:58.338+05:30</updated><title type='text'>ASP.NET Stack Collection</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;First, you create a new object of type&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;System.Collections.Stack&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;called&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;myStack&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;.You&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;then add items to the stack by using the &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Push&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;method and passing in the object you&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;want to add to the top of the stack.You can then retrieve items from the top of the stack .&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;(remember a stack is last-in-first-out, or LIFO) by using the&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Pop&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;method.The item is&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;returned as type of object, so if you need to convert it into a string, as in the following&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;example, you simply call the &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;ToString()&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;method. Otherwise, you'll need to cast it to&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;the type of object that you need.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;In &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;block or codebehind:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;'Make sure System.Collections is imported&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Dim myStack As New Stack()&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;myStack.Push("One")&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;myStack.Push("Two")&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;myStack.Push("Three")&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;While myStack.Count &amp;gt; 0&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Response.Write(myStack.Pop().ToString() &amp;amp; "&amp;lt;br&amp;gt;")&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End While&lt;/p&gt;&lt;br /&gt;&lt;p&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: RotisSansSerif"&gt;For more info see:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Stack class-&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;http://msdn.microsoft.com/library/en-us/cpref/html/&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;frlrfSystemCollectionsStackClassTopic.asp&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2911679513104798027?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2911679513104798027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2911679513104798027' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2911679513104798027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2911679513104798027'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/aspnet-stack-collection.html' title='ASP.NET Stack Collection'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6302386064996008225</id><published>2008-10-16T12:56:00.001+05:30</published><updated>2008-10-16T12:56:39.202+05:30</updated><title type='text'>ASP.NET Queue Collection</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Create a new object of type&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;System.Collections.Queue&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;called&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;myQueue&lt;/span&gt;&lt;font face="Bembo" size="2"&gt;. Add items to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the queue by using the &lt;font face="Courier" size="1"&gt;EnQueue&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method and passing in the object you want to add to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the queue.You can then retrieve items from the front of the queue (remember a queue&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;is first-in-first-out, or FIFO) by using the &lt;font face="Courier" size="1"&gt;DeQueue&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method.The item is returned as type&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;of object, so if you need to convert it into a string as in the following example, you simply&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;call the &lt;font face="Courier" size="1"&gt;ToString()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method. Otherwise, you'll need to cast it to the type of object&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that you need.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;'Make sure System.Collections is imported&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim myQueue As New Queue()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myQueue.Enqueue("One")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myQueue.Enqueue("Two")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myQueue.Enqueue("Three")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;While myQueue.Count &amp;gt; 0&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Write(myQueue.Dequeue().ToString() &amp;amp; "&amp;lt;br&amp;gt;")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End While&lt;/p&gt;&lt;br /&gt;&lt;p&gt;End Sub&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6302386064996008225?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6302386064996008225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6302386064996008225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6302386064996008225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6302386064996008225'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/aspnet-queue-collection.html' title='ASP.NET Queue Collection'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-4478291245922912924</id><published>2008-10-16T12:51:00.001+05:30</published><updated>2008-10-16T12:51:16.227+05:30</updated><title type='text'>ASP.NETHashTable Collection</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;&lt;strong&gt;You create a new object of type&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;System.Collections.HashTable&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;called&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;myHash&lt;/span&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Then, you add keys to the hash table by using the &lt;font face="Courier" size="1"&gt;add&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method and passing in the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;name and value of each key.You can then retrieve the values of each key by using&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;myHash("KeyName")&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.The value is returned as type of object, so if you need to convert it&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;into a string, as in the following example, you simply call the &lt;font face="Courier" size="1"&gt;ToString()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Otherwise, you'll need to cast it to the type of object that you need.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The ASPX page is as follows:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@Import namespace="System.Collections"%&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;%@Import namespace="System.Drawing"%&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;HTML&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;body&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;form method="post" runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;asp:Label ID="MyLabel" Runat="server"&amp;gt;Sample Text&amp;lt;/asp:Label&amp;gt;&amp;lt;br&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/body&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/HTML&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim myHash As New Hashtable()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myHash.Add("Red", "#FF0000")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myHash.Add("Green", "#00FF00")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myHash.Add("Blue", "#0000FF")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MyLabel.BackColor=ColorTranslator.FromHtml(myHash("Blue").ToString())&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MyLabel.ForeColor=ColorTranslator.FromHtml(myHash("Red").ToString())&lt;/p&gt;&lt;br /&gt;&lt;p&gt;End Sub&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4478291245922912924?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4478291245922912924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4478291245922912924' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4478291245922912924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4478291245922912924'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/aspnethashtable-collection.html' title='ASP.NETHashTable Collection'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-542858041779547731</id><published>2008-10-16T12:46:00.001+05:30</published><updated>2008-10-16T12:46:31.036+05:30</updated><title type='text'>ASP.NET Creating Custom Collection</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;A custom collection class allows the use of the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;For Each&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;syntax (&lt;/span&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;foreach&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;in C#) to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;loop through a set of custom typed items.The custom collection class must internally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;keep references to the items with an array or other type of collection (&lt;/font&gt;&lt;font face="Courier" size="1"&gt;ArrayList&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;,&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;HashTable&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;).The .NET Framework then requires the following two interfaces to be&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;implemented in order to support the &lt;font face="Courier" size="1"&gt;For Each&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;syntax:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;System.Collections.IEnumerable&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;Function GetEnumerator() As IEnumerator&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;System.Collections.IEnumerator&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Reset()&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;Function MoveNext() As Boolean&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;font face="Courier" size="1"&gt;ReadOnly Property Current As Object&lt;/font&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load()&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _customCollection As CustomCollection&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _customItem As CustomItem&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _index As Integer&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_customCollection = New CustomCollection(10)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;For Each _customItem In _customCollection&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_index = _customItem.Index&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Next&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Custom Collection defined in CustomCollection.vb&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Class CustomCollection&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Implements IEnumerable, IEnumerator&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Private customItems() As CustomItem&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Private currentIndex As Integer = -1&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Sub New(ByVal Count As Integer)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim index As Integer&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ReDim customItems(Count - 1)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;For index = 0 To Count - 1&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;customItems(index) = New CustomItem(index)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Next&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;#Region "Implementation of IEnumerable"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Function GetEnumerator() As Ienumerator&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;Implements IEnumerable.GetEnumerator&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Return CType(Me, IEnumerator)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Function&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;#End Region&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;#Region "Implementation of IEnumerator"&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Sub Reset() Implements IEnumerator.Reset&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;currentIndex = -1&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If currentIndex &amp;lt; customItems.Length - 1 Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;currentIndex = currentIndex + 1&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Return True&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Else&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Return False&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Function&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public ReadOnly Property Current() As Object&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;Implements IEnumerator.Current&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Get&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Return customItems(currentIndex)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Get&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Property&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;#End Region&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Class&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Custom Item defined in CustomItem.vb&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Class CustomItem&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Private _index As Integer&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public ReadOnly Property Index() As Integer&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Get&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Return _index&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Get&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Property&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Sub New(ByVal Index As Integer)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_index = Index&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Class&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;This implementation uses a simple array of the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;CustomItem&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;type and offers nothing&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;beyond the &lt;font face="Courier" size="1"&gt;For Each&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;support. It can be easily extended to support additional array or&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;ArrayList&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;methods, such as&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Count/Length&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;and&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Item&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.The base collection type can also&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;be changed to &lt;font face="Courier" size="1"&gt;ArrayList&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;or&lt;/font&gt; &lt;font face="Courier" size="1"&gt;HashTable&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;for further functionality.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This implementation of the &lt;font face="Courier" size="1"&gt;CustomItem&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;type is no more than a contrived example&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;with a single property of &lt;font face="Courier" size="1"&gt;Index&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. It should be extended to include the various properties&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;and methods relevant to the actual custom item.The construction of the item, or set of&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;items, can also come from an external data store.&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-542858041779547731?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/542858041779547731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=542858041779547731' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/542858041779547731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/542858041779547731'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/aspnet-creating-custom-collection.html' title='ASP.NET Creating Custom Collection'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-2332482723936955728</id><published>2008-10-16T12:00:00.001+05:30</published><updated>2008-10-16T12:00:57.548+05:30</updated><title type='text'>How to Declare Collections in ASP.NET</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The .NET Framework includes a number of commonly used collections.They are found in the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;System.Collections&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;namespace, and can hold any object type, which means they&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;can hold &lt;em&gt;&lt;font face="Bembo-Italic" size="2"&gt;any&lt;/font&gt;&lt;/em&gt; &lt;font face="Bembo" size="2"&gt;type, because in .NET, all types inherit from object.This example demonstrates&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;this using a simple array list.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load (Sender As Object, E As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim al As New ArrayList(5)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;al.Add("one")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;al.Add(2)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;al.Add(False)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;al.Add(New System.Object())&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;Response.Write("Successfully added " &amp;amp; al.Count &amp;amp; _&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;" different types of objects to an ArrayList.")&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Declaring and using collections in .NET is very straightforward. Later in this chapter,&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;you'll learn how to use some of the different collections included in the framework, as&lt;/p&gt;&lt;br /&gt;&lt;p&gt;well as how to create your own strongly typed collections.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2332482723936955728?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2332482723936955728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2332482723936955728' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2332482723936955728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2332482723936955728'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/how-to-declare-collections-in-aspnet.html' title='How to Declare Collections in ASP.NET'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6154546464913653909</id><published>2008-10-10T00:00:00.001+05:30</published><updated>2008-10-10T00:00:28.859+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Loading User Controls ASP.NET'/><title type='text'>Load User Controls Programmatically</title><content type='html'>&lt;p class="first-para"&gt;User controls are self-contained groups of controls. Like Web forms, user controls consist of a layout portion that defines the contained controls (.ascx file) and a code-behind portion with the event-handling logic (.cs file). User controls allow you to reuse common interface elements on multiple pages and build complex interfaces out of smaller building blocks. One useful characteristic of user controls is that they can be loaded programmatically, which allows you to create a highly configurable interface that you can tailor dynamically according to the user. You simply load the control, configure its properties, and then add it to another container control.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The basic solution could be implemented in a more object-oriented way by creating a custom user control that encapsulates the dynamic graphic. The user control could allow the page to set the text, font, colors, and so on through various properties. Here's an example of what the custom control would look like:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;public class DynamicGraphicControl : System.Web.UI.UserControl {&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private string imageText = "";&lt;br /&gt;    public string ImageText {&lt;br /&gt;        get {&lt;br /&gt;            return imageText;&lt;br /&gt;        }&lt;br /&gt;        set {&lt;br /&gt;            imageText = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private Font textFont;&lt;br /&gt;    public Font TextFont {&lt;br /&gt;        get {&lt;br /&gt;            return textFont;&lt;br /&gt;        }&lt;br /&gt;        set {&lt;br /&gt;            textFont = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private Size imageSize;&lt;br /&gt;    public Size ImageSize {&lt;br /&gt;        get {&lt;br /&gt;            return imageSize;&lt;br /&gt;        }&lt;br /&gt;        set {&lt;br /&gt;            imageSize = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private Color foreColor;&lt;br /&gt;    public Color ForeColor {&lt;br /&gt;        get {&lt;br /&gt;            return foreColor;&lt;br /&gt;        }&lt;br /&gt;        set {&lt;br /&gt;            foreColor = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private Color backColor;&lt;br /&gt;    public Color BackColor {&lt;br /&gt;        get {&lt;br /&gt;            return backColor;&lt;br /&gt;        }&lt;br /&gt;        set {&lt;br /&gt;            backColor = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private Color borderColor;&lt;br /&gt;    public Color BorderColor {&lt;br /&gt;        get {&lt;br /&gt;            return borderColor;&lt;br /&gt;        }&lt;br /&gt;        set {&lt;br /&gt;            borderColor = value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;        if (ImageText == "")&lt;br /&gt;            return;&lt;br /&gt;&lt;br /&gt;        // Create an in-memory bitmap where you will draw the image. &lt;br /&gt;        Bitmap bitmap = new Bitmap(ImageSize.Width, ImageSize.Height);&lt;br /&gt;&lt;br /&gt;        // Get the graphics context for the bitmap.&lt;br /&gt;        Graphics graphics = Graphics.FromImage(bitmap);&lt;br /&gt;&lt;br /&gt;        // Set the background color and rendering quality.&lt;br /&gt;        // This color will become the border&lt;br /&gt;        graphics.Clear(BorderColor);&lt;br /&gt;        graphics.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;&lt;br /&gt;        // Paint a rectangle.&lt;br /&gt;        graphics.FillRectangle(new SolidBrush(BackColor), 5, 5, &lt;br /&gt;          ImageSize.Width - 10, ImageSize.Height - 10);&lt;br /&gt;&lt;br /&gt;        // Set the alignment for the text.&lt;br /&gt;        StringFormat stringFormat = new StringFormat();&lt;br /&gt;        stringFormat.Alignment = StringAlignment.Center;&lt;br /&gt;        stringFormat.LineAlignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;        // Paint the text.&lt;br /&gt;        graphics.DrawString(ImageText, TextFont, new SolidBrush(ForeColor), &lt;br /&gt;          new Rectangle(0, 0, ImageSize.Width, ImageSize.Height), &lt;br /&gt;          stringFormat);&lt;br /&gt;&lt;br /&gt;        // Render the image to the HTML output stream.&lt;br /&gt;        bitmap.Save(Response.OutputStream, &lt;br /&gt;        System.Drawing.Imaging.ImageFormat.Gif);&lt;br /&gt;&lt;br /&gt;        graphics.Dispose();&lt;br /&gt;        bitmap.Dispose();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="para"&gt;The Web form loads this user control in the &lt;em&gt;Page.Load&lt;/em&gt; event handler. The user control is placed in a &lt;em&gt;Panel&lt;/em&gt; control container. The &lt;em&gt;LoadControl&lt;/em&gt; method returns a generic &lt;em&gt;Control&lt;/em&gt; object, which the code casts to the appropriate user control class.&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Drawing;&lt;br /&gt;&lt;br /&gt;public class DynamicControlTest : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    protected System.Web.UI.WebControls.Panel pnl;&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;        // Load the control. &lt;br /&gt;        DynamicGraphicControl ctrl;&lt;br /&gt;        ctrl = (DynamicGraphicControl)&lt;br /&gt;          Page.LoadControl("DynamicGraphicControl.ascx");&lt;br /&gt;&lt;br /&gt;        // Configure the control properties.&lt;br /&gt;        ctrl.ImageText = "This is a new banner test";&lt;br /&gt;        ctrl.ImageSize = new Size(300, 200);&lt;br /&gt;        ctrl.TextFont = new Font("Verdana", 24, FontStyle.Bold);&lt;br /&gt;        ctrl.BackColor = Color.Olive;&lt;br /&gt;        ctrl.ForeColor = Color.LightYellow;&lt;br /&gt;        ctrl.BorderColor = Color.OrangeRed;&lt;br /&gt;&lt;br /&gt;        // Add the control to the page.&lt;br /&gt;        pnl.Controls.Add(ctrl);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="para"&gt;In Visual Studio .NET, the user control class is always available because classes are compiled into a single .dll assembly. If the user control is not a part of the project, however, you won't have the required user control class and you won't be able to access any of the user control's properties or methods. To remedy this problem, you can define a base class or an interface that defines the basic functionality you need to be able to access in any of your custom user controls.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Loading+User+Controls+ASP.NET" class="ztag" rel="tag"&gt;Loading User Controls ASP.NET&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6154546464913653909?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6154546464913653909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6154546464913653909' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6154546464913653909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6154546464913653909'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/load-user-controls-programmatically.html' title='Load User Controls Programmatically'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-1106458938132354856</id><published>2008-10-09T23:56:00.001+05:30</published><updated>2008-10-09T23:56:14.500+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Rending Image in ASP.NET'/><title type='text'>Dynamically Render an Image</title><content type='html'>&lt;p class="first-para"&gt;You can draw dynamic graphics using the same GDI+ code in a Web application that you'd use in a Windows-based application. The only difference is how you render the final graphic. There are basically two approaches that you can use.&lt;/p&gt;&lt;br /&gt;&lt;ul class="itemizedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;You can stream the binary contents of the image directly to the &lt;em&gt;OutputStream&lt;/em&gt; property of the &lt;em&gt;HttpResponse&lt;/em&gt; object. This is a good approach if you need to generate a wide range of images and don't want to clutter the server hard drive with image files that won't be used again. It's also the best choice if you need to create dynamic images that are tailored to match user input.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;You can save the image to the Web server's file system and use an HTML &amp;lt;&lt;em&gt;img&lt;/em&gt;&amp;gt; tag to display the created image. This is a good choice if you need to create a graphic that will be reused because it will avoid the overhead of continuously re-creating the graphic.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p class="para"&gt;This post explores both approaches. First we'll consider how to dynamically create an image without saving it to a file. In this example, the goal is to create a simple banner&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;You'll notice that the only user-supplied value in this example is the banner text itself, which is supplied through the query string. The font, colors, and dimensions are hard-coded (although they could easily be set based on other query string parameters or Web.config defaults).&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;Here's the full page code:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;public class DynamicGraphic : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;    &lt;br /&gt;        // Get the text from the query string.&lt;br /&gt;        // If no text is supplied, choose a default.&lt;br /&gt;        string text = "";&lt;br /&gt;        if (Request.QueryString["image"] == null) {&lt;br /&gt;        &lt;br /&gt;            Response.Redirect(Request.Url + "?image=" +&lt;br /&gt;            Server.UrlEncode("This is a test image"));&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;            text = Server.UrlDecode(Request.QueryString["image"]);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;   // Create an in-memory bitmap where you will draw the image. &lt;br /&gt;            // The Bitmap is 300 pixels wide and 200 pixels high.   &lt;br /&gt;            int width = 300, height = 200;&lt;br /&gt;            Bitmap bitmap = new Bitmap(width, height);&lt;br /&gt;&lt;br /&gt;            // Get the graphics context for the bitmap.&lt;br /&gt;            Graphics graphics = Graphics.FromImage(bitmap);&lt;br /&gt;&lt;br /&gt;            // Set the background color and rendering quality.&lt;br /&gt;            // This color will become the border&lt;br /&gt;            graphics.Clear(Color.OrangeRed);&lt;br /&gt;            graphics.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;&lt;br /&gt;            // Paint a rectangle.&lt;br /&gt;            graphics.FillRectangle(new SolidBrush(Color.Olive), 5, 5, &lt;br /&gt;              width - 10, height - 10);&lt;br /&gt;&lt;br /&gt;            // Choose a font and alignment for the text.&lt;br /&gt;            Font fontBanner = new Font("Verdana", 24, FontStyle.Bold);&lt;br /&gt;            StringFormat stringFormat = new StringFormat();&lt;br /&gt;            stringFormat.Alignment = StringAlignment.Center;&lt;br /&gt;            stringFormat.LineAlignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;            // Paint the text.&lt;br /&gt;            graphics.DrawString(text, fontBanner, new &lt;br /&gt;            SolidBrush(Color.LightYellow), new Rectangle(0, 0, width, height), &lt;br /&gt;              stringFormat);&lt;br /&gt;&lt;br /&gt;            // Render the image to the HTML output stream.&lt;br /&gt;            bitmap.Save(Response.OutputStream, &lt;br /&gt;              System.Drawing.Imaging.ImageFormat.Gif);&lt;br /&gt;&lt;br /&gt;            graphics.Dispose();&lt;br /&gt;            bitmap.Dispose();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="para"&gt;When you save an image to the response stream, you replace any other output. Therefore, you can't use this technique with a page that also includes Web controls or static HTML content. Thus, if you want to use a page that combines dynamically generated images and Web controls, you need to wrap the dynamically generated image in a control or write the image to the hard drive before displaying it.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;If you want to save the file to the hard drive, you move the image generation code into a separate method, which we'll call &lt;em&gt;GenerateBanner&lt;/em&gt;. Then, in the &lt;em&gt;Page.Load&lt;/em&gt; event handler, you begin by checking to see whether the file already exists by using the &lt;em&gt;static&lt;/em&gt; &lt;em&gt;File.Exists&lt;/em&gt; method. If the file doesn't exist, you generate it in memory by calling &lt;em&gt;GenerateBanner&lt;/em&gt; and save it using the &lt;em&gt;Bitmap.Save&lt;/em&gt; method. Otherwise, you simply load the image directly.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The following code shows the basic approach you must take:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;public class DynamicGraphic : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    protected System.Web.UI.WebControls.Image imageControl;&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private Bitmap GenerateBanner() {&lt;br /&gt;    &lt;br /&gt;        // Create the image using the same code as in the previous example.&lt;br /&gt;        // (Code omitted.)&lt;br /&gt;    }    &lt;br /&gt;&lt;br /&gt;    private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;    &lt;br /&gt;        // Set the filename based on the image text.&lt;br /&gt;        // We assume this only includes characters that are&lt;br /&gt;        // legal for a filename.&lt;br /&gt;        string fileName = Request.QueryString["image"] + ".gif";&lt;br /&gt;&lt;br /&gt;        Bitmap bitmap = null;&lt;br /&gt;&lt;br /&gt;        // Check if an image with this text already exists.&lt;br /&gt;        if (File.Exists(fileName)) {&lt;br /&gt;&lt;br /&gt;            // Load the existing image.&lt;br /&gt;            try {&lt;br /&gt;                bitmap = new Bitmap(fileName);&lt;br /&gt;            }catch {&lt;br /&gt;                bitmap = GenerateBanner();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;            bitmap = GenerateBanner();&lt;br /&gt;&lt;br /&gt;            // Save the image.&lt;br /&gt;            bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Gif);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // Display the image by setting an Image property.&lt;br /&gt;        imageControl.ImageUrl = fileName;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Rending+Image+in+ASP.NET" class="ztag" rel="tag"&gt;Rending Image in ASP.NET&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-1106458938132354856?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/1106458938132354856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=1106458938132354856' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1106458938132354856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1106458938132354856'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/dynamically-render-image.html' title='Dynamically Render an Image'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-4448528903562184009</id><published>2008-10-09T23:51:00.001+05:30</published><updated>2008-10-09T23:51:33.349+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Adding Controls ASP.NET form'/><title type='text'>Add Controls to Web Form Dynamically</title><content type='html'>&lt;p class="first-para"&gt;You can use a technique to add Web controls to a Web page that's similar to the way you would add Windows controls to a form, but there are some differences, including the following:&lt;/p&gt;&lt;br /&gt;&lt;ul class="itemizedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;Dynamically added controls will exist only until the next postback. If you need them, you must re-create them when the page is returned. This requirement doesn't prevent you from writing code that handles their events, however.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;Dynamically added controls aren't as easy to position. Typically, you'll use literal controls containing HTML code (such as the line break &amp;lt;&lt;em&gt;br&lt;/em&gt;&amp;gt;) to separate more than one dynamically created control.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;Dynamically created controls should be placed in a container control (such as a &lt;em&gt;Panel&lt;/em&gt; or a &lt;em&gt;LiteralControl&lt;/em&gt;) rather than directly on the page itself, which makes it easier to position them.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;If you want to interact with the control later, you should give it a unique ID. You can use this ID to retrieve the control from the &lt;em&gt;Controls&lt;/em&gt; collection of its container.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p class="para"&gt;The best place to generate new controls is in the &lt;em&gt;Page.Load&lt;/em&gt; event handler, which ensures that the control will be created each time the page is served. In addition, if you're adding an input control that uses view state, the view state information will be restored to the control after the &lt;em&gt;Page.Load&lt;/em&gt; event fires. That means a dynamically generated text box will retain its text over multiple postbacks, just like a text box that's defined in the .aspx file. Similarly, because the &lt;em&gt;Page.Load&lt;/em&gt; event always fires before any other events take place, you can re- create a control that raises server-side events and its event-handling code will be triggered immediately after the &lt;em&gt;Page.Load&lt;/em&gt; event. For example, this technique allows you to dynamically generate a button that can respond to user clicks.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The following example demonstrates all these concepts. It generates three dynamic server controls (two buttons and a text box) and positions them using literal controls that act as separators. The buttons are connected to distinct event handlers. The text box is given a unique identifier so that its text can be retrieved later, in response to the button clicks.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The full code is shown here:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;&lt;br /&gt;public class DynamicControls : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    protected System.Web.UI.WebControls.Label lblMessage;&lt;br /&gt;    protected System.Web.UI.WebControls.Panel pnl;&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;    &lt;br /&gt;        // Create a dynamic button.&lt;br /&gt;        Button dynamicButton = new Button();&lt;br /&gt;        dynamicButton.Text = "Dynamic Button A";&lt;br /&gt;&lt;br /&gt;        // Connect an event handler.&lt;br /&gt;        dynamicButton.Click += new EventHandler(cmdDynamicA_Click);&lt;br /&gt;&lt;br /&gt;        // Add the button to a Panel.&lt;br /&gt;        pnl.Controls.Add(dynamicButton);&lt;br /&gt;            &lt;br /&gt;        // Add a line break separator.&lt;br /&gt;        pnl.Controls.Add(new LiteralControl("&amp;lt;br&amp;gt;"));&lt;br /&gt;&lt;br /&gt;        // Create a second dynamic button.&lt;br /&gt;        dynamicButton = new Button();&lt;br /&gt;        dynamicButton.Text = "Dynamic Button B";&lt;br /&gt;        dynamicButton.Click += new EventHandler(cmdDynamicB_Click);&lt;br /&gt;        pnl.Controls.Add(dynamicButton);&lt;br /&gt;&lt;br /&gt;        // Add a line break separator.&lt;br /&gt;        pnl.Controls.Add(new LiteralControl("&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;"));&lt;br /&gt;&lt;br /&gt;        // Create a dynamic textbox.&lt;br /&gt;        TextBox dynamicText = new TextBox();&lt;br /&gt;        pnl.Controls.Add(dynamicText);&lt;br /&gt;&lt;br /&gt;        // Assign a unique ID so the textbox can be retrieved&lt;br /&gt;        // from the control collection later.&lt;br /&gt;        dynamicText.ID = "DynamicText";&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void cmdDynamicA_Click(object sender, System.EventArgs e) {&lt;br /&gt;    &lt;br /&gt;        lblMessage.Text = "Clicked A";&lt;br /&gt;        GetText();&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private void cmdDynamicB_Click(object sender, System.EventArgs e) {&lt;br /&gt;    &lt;br /&gt;        lblMessage.Text = "Clicked B";&lt;br /&gt;        GetText();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void GetText(){&lt;br /&gt;        lblMessage.Text += "&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;";&lt;br /&gt;&lt;br /&gt;        foreach (Control ctrl in pnl.Controls){&lt;br /&gt;            if (ctrl.ID == "DynamicText"){&lt;br /&gt;                lblMessage.Text += "TextBox contains: " +&lt;br /&gt;                  ((TextBox)ctrl).Text;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="last-para"&gt;If you need to dynamically create complex layouts that include some prebuilt control "groups," you might prefer to use user controls and load them dynamically into a page.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Adding+Controls+ASP.NET+form" class="ztag" rel="tag"&gt;Adding Controls ASP.NET form&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4448528903562184009?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4448528903562184009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4448528903562184009' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4448528903562184009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4448528903562184009'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/add-controls-to-web-form-dynamically.html' title='Add Controls to Web Form Dynamically'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-7510382542528477447</id><published>2008-10-09T23:46:00.001+05:30</published><updated>2008-10-09T23:46:46.792+05:30</updated><title type='text'>Perform Selective Input Validation</title><content type='html'>&lt;p class="first-para"&gt;The ASP.NET validation controls are an ideal solution for quickly validating forms. They work well as long as you want to validate an entire page at a time. If you want to validate only part of a form, or you want to make a programmatic decision about whether to validate a control (perhaps based on the validation success or value of another control), you'll need to use selective validation.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The first step in selective validation is to disable the &lt;em&gt;EnableClientScript&lt;/em&gt; property of every validation control on your page. Otherwise, validation will be performed at the client through JavaScript, the page won't be posted back if it contains invalid values, and your event handling code won't be executed. Once you've made this change, you can validate the page one control at a time using the &lt;em&gt;BaseValidator.Validate&lt;/em&gt; method, or you can validate the entire page using the &lt;em&gt;Page.Validate&lt;/em&gt; method.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The following example uses server-side validation with two validators: a &lt;em&gt;RangeValidator&lt;/em&gt; and a &lt;em&gt;RegularExpressionValidator&lt;/em&gt; (which validates an e-mail address). If validation fails, the code steps through the collection of validators on the form using the &lt;em&gt;Page.Validators&lt;/em&gt; property. Every time the code finds a failed validator, it finds the corresponding control using the &lt;em&gt;Page.FindControl&lt;/em&gt; method and then displays the offending value (a trick that's not possible with automatic validation).&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;&lt;br /&gt;public class SelectiveValidation : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    protected System.Web.UI.WebControls.TextBox txtNumber;&lt;br /&gt;    protected System.Web.UI.WebControls.TextBox txtEmail;&lt;br /&gt;    protected System.Web.UI.WebControls.Label lblCustomSummary;&lt;br /&gt;    protected System.Web.UI.WebControls.RegularExpressionValidator&lt;br /&gt;      validatorEmail;&lt;br /&gt;    protected System.Web.UI.WebControls.RangeValidator validatorNumber;&lt;br /&gt;    protected System.Web.UI.WebControls.Button cmdValidate;&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private void cmdValidate_Click(object sender, System.EventArgs e) {&lt;br /&gt;    &lt;br /&gt;        // Validate the page.&lt;br /&gt;        this.Validate();&lt;br /&gt;&lt;br /&gt;        if (!Page.IsValid) {&lt;br /&gt;        &lt;br /&gt;            lblCustomSummary.Text = "";&lt;br /&gt;            foreach (BaseValidator validator in this.Validators) {&lt;br /&gt;            &lt;br /&gt;                if (!validator.IsValid) {&lt;br /&gt;                &lt;br /&gt;                    TextBox invalidControl = (TextBox)&lt;br /&gt;                      this.FindControl(validator.ControlToValidate);&lt;br /&gt;&lt;br /&gt;                    lblCustomSummary.Text +=&lt;br /&gt;                      "The page contains the following error: &amp;lt;b&amp;gt;" +&lt;br /&gt;                      validator.ErrorMessage + "&amp;lt;/b&amp;gt;.&amp;lt;br&amp;gt;" +&lt;br /&gt;                      "The invalid input is: &amp;lt;b&amp;gt;" +&lt;br /&gt;                      invalidControl.Text + "&amp;lt;/b&amp;gt;." + "&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;";&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }else {&lt;br /&gt;            lblCustomSummary.Text = "Validation succeeded.";&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7510382542528477447?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7510382542528477447/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7510382542528477447' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7510382542528477447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7510382542528477447'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/perform-selective-input-validation.html' title='Perform Selective Input Validation'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-5920115379873317566</id><published>2008-10-06T13:02:00.006+05:30</published><updated>2008-10-07T21:21:13.178+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Forms Authentication'/><title type='text'>Use Forms Authentication</title><content type='html'>To prevent users from accessing certain pages unless they have first authenticated themselves with a custom logon page.&lt;br /&gt;&lt;br /&gt;&lt;div class="first-para"&gt;Forms authentication is a flexible security model that allows you to prevent unauthenticated users from accessing certain pages. You write the code that performs the authentication, and ASP.NET issues a cookie to authenticated users. Users without the cookie are redirected to a login page when they try to access a secured page.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;To implement forms authentication, you must take the following steps:&lt;/div&gt;&lt;ul class="itemizedlist"&gt;&lt;li class="first-listitem"&gt;  &lt;br /&gt;&lt;br /&gt;&lt;div class="first-para"&gt;Configure forms authentication using the &amp;lt;&lt;i&gt;authentication&lt;/i&gt;&amp;gt; tag in the application's Web.config file.&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;li class="listitem"&gt;  &lt;br /&gt;&lt;br /&gt;&lt;div class="first-para"&gt;Restrict anonymous users from a specific page or directory using Web.config settings.&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;li class="listitem"&gt;  &lt;br /&gt;&lt;br /&gt;&lt;div class="first-para"&gt;Create the logon page, and add your authentication logic, which leverages the &lt;i&gt;FormsAuthentication&lt;/i&gt; class from the &lt;i&gt;System.Web.Security&lt;/i&gt; namespace.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="para"&gt;The first step is to configure the Web.config in the root application directory to enable forms authentication, as shown in the following code. You also need to specify your custom login page (where unauthenticated users will be redirected) and a time-out after which the cookie will be removed. The authentication cookie is automatically renewed with each Web request.&lt;/div&gt;&lt;br /&gt;&lt;span style="border-collapse: separate; color: black; font-family: -webkit-monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;configuration&gt;&lt;br /&gt;&lt;system.web&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;&lt;b&gt;authentication mode="Forms"&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;forms loginUrl="login.aspx" timeout="30" /&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/authentication&lt;/b&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/system.web&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="para"&gt;Next you need to add an authorization rule denying anonymous users. The easiest way to secure pages is to create a subdirectory with its own Web.config file. The Web.config file should refuse access to anonymous users, as shown here:&lt;/div&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;configuration&gt;  &lt;br /&gt;&lt;system.web&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;&lt;b&gt;authorization&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;deny users="?" /&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/authorization&lt;/b&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/system.web&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="para"&gt;Now ASP.NET will automatically forward unauthenticated requests for pages in this subdirectory to the custom logon page.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;Another option is to specifically deny access to specific pages in the current directory by using the &amp;lt;&lt;i&gt;location&lt;/i&gt;&amp;gt; tag:&lt;/div&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;configuration&gt;  &lt;br /&gt;&lt;system.web&gt;&lt;br /&gt;&lt;br /&gt;&lt;/system.web&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;&lt;b&gt;location path="SecurePage.aspx"&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;system.web&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;authorization&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;deny users="?" /&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/authorization&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/system.web&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/location&lt;/b&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="para"&gt;You can also deny specific users by entering a comma-separated list of user names instead of the wildcard (?) character, which simply means "all anonymous users."&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;You need to create the logon page. Your logon page can authenticate the user using a hard-coded password (suitable for simple tests), a server-side database, or any other type of custom authentication logic. Once the user has been successfully authenticated, call the &lt;i&gt;static&lt;/i&gt; &lt;i&gt;FormsAuthentication.RedirectFromLoginPage&lt;/i&gt; method with the username. This method simultaneously sets the forms authentication cookie and redirects the user to the originally requested page.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;Here's a rudimentary logon page that simply checks for a specific password when the user clicks a logon button:&lt;/div&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;&lt;br /&gt;public class LoginPage : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;protected System.Web.UI.WebControls.Label lblStatus;&lt;br /&gt;protected System.Web.UI.WebControls.Button cmdLogin;&lt;br /&gt;protected System.Web.UI.WebControls.TextBox txtPassword;&lt;br /&gt;protected System.Web.UI.WebControls.TextBox txtName;&lt;br /&gt;&lt;br /&gt;// (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;private void cmdLogin_Click(object sender, System.EventArgs e){&lt;br /&gt;if (txtPassword.Text.ToLower() == "secret") {&lt;br /&gt;FormsAuthentication.RedirectFromLoginPage(txtName.Text, false);&lt;br /&gt;&lt;br /&gt;}else {&lt;br /&gt;lblStatus.Text = "Try again.";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="last-para"&gt;To test this page with the sample code that accompanies the book, request SecurePage.aspx, which is placed in a secured directory. You'll be redirected to login.aspx, and provided you submit the correct password, you'll be returned to SecurePage.aspx.&lt;/div&gt;&lt;br /&gt;&lt;div class="zoundry_raven_tags" xmlns=""&gt;&lt;br /&gt;&lt;br /&gt;Technorati : &lt;a class="ztag" href="http://www.technorati.com/tag/Forms+Authentication" rel="tag"&gt;Forms Authentication&lt;/a&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5920115379873317566?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5920115379873317566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5920115379873317566' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5920115379873317566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5920115379873317566'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/use-forms-authentication.html' title='Use Forms Authentication'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-918014744348909189</id><published>2008-10-06T12:52:00.003+05:30</published><updated>2008-10-06T13:03:32.718+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='IIS Authentication'/><title type='text'>Using IIS Authentication</title><content type='html'>To prevent users from accessing certain pages unless they have been authenticated against a Windows user account on the server.&lt;br /&gt;&lt;br /&gt;&lt;div class="first-para"&gt;IIS and ASP.NET use a layered security model. When a user requests an ASP.NET Web page over HTTP, the following steps take place:&lt;/div&gt;&lt;ol class="orderedlist"&gt;&lt;li class="first-listitem"&gt; &lt;br /&gt;&lt;div class="first-para"&gt;IIS attempts to authenticate the user. If anonymous access is enabled, IIS automatically logs the user on as the anonymous user (typically the IUSR_[ServerName] account). Otherwise, it requests authentication credentials that it will use to log the user on with another Windows account.&lt;/div&gt;&lt;div class="first-para"&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class="listitem"&gt; &lt;br /&gt;&lt;div class="first-para"&gt;Provided IIS can authenticate the user successfully, it passes the request to ASP.NET with information about the authenticated user. ASP.NET can then use its own security services based on the settings in the Web.config file (for example, denying specific users or groups access to certain pages or directories). In addition, your code can restrict actions programmatically by checking the user information.&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;li class="listitem"&gt; &lt;br /&gt;&lt;div class="first-para"&gt;If the ASP.NET code accesses any system resources (for example, tries to open a file or connect to a database), the Windows operating system performs its own security checks. Usually, the ASP.NET application code won't actually run under the account of the authenticated user. Thus, these security checks are made against the ASP.NET process account (which is configured using the machine.config file).&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="para"&gt;The first step to use IIS authentication is to disable anonymous access for the virtual directory. To do so, start IIS Manager (select Settings | Control Panel | Administrative Tools | Internet Information Services from the Start Menu). Then right-click a virtual directory or a subdirectory inside a virtual directory, and choose Properties. Select the Directory Security tab, as shown in below figure.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;&lt;img alt="figure1.JPG" height="274" src="http://img137.imageshack.us/img137/8050/figure1ee9.jpg" width="281" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;Next, click the Edit button to modify the directory security settings. The window shown below figure will appear. In the bottom half of the window, you can enable one of the Windows authentication methods. However, none of these methods will be used unless you explicitly clear the Anonymous Access check box.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;&lt;img alt="figure2.JPG" height="262" src="http://img137.imageshack.us/img137/4271/figure2ax5.jpg" width="228" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;You can enable more than one authentication method, in which case the client will use the strongest supported method. If anonymous access is enabled, it's always used. The different authentication methods are described in Table 7. 2.&lt;/div&gt;&lt;div class="para"&gt;&lt;/div&gt;&lt;table border="1" class="table" style="margin-left: 10px;"&gt;&lt;caption class="table-title"&gt;Table 7.2: Types of Authentication&lt;/caption&gt; &lt;thead&gt;&lt;tr valign="top"&gt; &lt;th align="left" class="th" scope="col" width="21%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Mode&lt;/div&gt;&lt;/th&gt; &lt;th align="left" class="th" scope="col" width="79%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Description&lt;/div&gt;&lt;/th&gt; &lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="21%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Anonymous&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="79%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;The client is not required to submit any information. Users are logged in using the preset anonymous account (typically IUSR_[ServerName]).&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="21%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Basic&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="79%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Basic authentication is a part of the HTTP 1.0 standard, and it is supported by almost all browsers and Web servers. When using basic authentication, the browser presents the user with a login box with a user name and password field. This information is then transmitted to IIS, where it is matched with a local Windows user account. Basic authentication should always be combined with SSL because it doesn't encrypt the logon information before transmitting it.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="21%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Digest&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="79%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Digest authentication sends a digest (also known as a cryptographic hash) over the network. Thus, it's much more secure than Basic authentication because intercepted logon information can't be reused. The primary disadvantage is that Digest authentication is supported only by Internet Explorer 5.0 and later versions. Also, your Web server needs to use Active Directory or have access to an Active Directory server.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="21%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Integrated&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="79%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Integrated Windows authentication is the best choice for most intranet scenarios. When using integrated authentication, Internet Explorer sends the logon token for the current user automatically, provided it is on a trusted domain. Integrated authentication is supported only on Internet Explorer 2.0 and later and can't work over proxy servers.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;&lt;div class="para"&gt;Once you've enabled the appropriate virtual directory security settings, you should make sure that the Web.config file is set to use Windows authentication. In a Visual Studio .NET project, this is the default setting.&lt;/div&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;lt;system.web&amp;gt;&lt;br /&gt;&amp;lt;!-- Other settings omitted. --&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;authentication mode="Windows" /&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="para"&gt;At this point, your virtual directory will require user authentication and your Web application will be able to retrieve the user information. In addition, you can add authorization rules that prevent certain users or groups from accessing Web pages or subdirectories. You do this by adding &amp;lt;&lt;i&gt;allow&lt;/i&gt;&amp;gt; and &amp;lt;&lt;i&gt;deny&lt;/i&gt;&amp;gt; tags to the &amp;lt;&lt;i&gt;authorization&lt;/i&gt;&amp;gt; section of the Web.config file. For example, you can create a subdirectory with the following Web.config file contents:&lt;/div&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;lt;system.web&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;authorization&amp;gt;&lt;br /&gt;&amp;lt;deny roles="Guest,Associate" /&amp;gt;&lt;br /&gt;&amp;lt;allow users="matthew" /&amp;gt;&lt;br /&gt;&amp;lt;deny users="*" /&amp;gt;&lt;br /&gt;&amp;lt;/authorization&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="para"&gt;ASP.NET examines rules in the order they appear and stops when it finds a match. In this example, users in the Guest or Associate groups will automatically be denied. The user matthew will be permitted (unless he's a member of one of the previously forbidden groups). All other users will be denied. In this case, these are local groups and user accounts. If you want to refer to a domain account, use the pathlike syntax [DomainName]\[UserName] instead.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;Notice that in this example, the Web.config file doesn't contain an &amp;lt;&lt;i&gt;authentication&lt;/i&gt;&amp;gt; section. This omission is because the authentication is configured in the Web.config file in the Web application directory. Subdirectories can set their own authorization rules, but they can't change the mode of authentication.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;Another option is to deny access to specific pages using the &amp;lt;&lt;i&gt;location&lt;/i&gt;&amp;gt; attribute:&lt;/div&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&amp;lt;configuration&amp;gt;  &lt;br /&gt;&amp;lt;system.web&amp;gt;&lt;br /&gt;&amp;lt;!-- Other settings omitted. --&amp;gt;&lt;br /&gt;&amp;lt;/system.web&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;&lt;b&gt;location path="SecurePage.aspx"&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;system.web&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;authorization&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;deny roles="Guest" /&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/authorization&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/system.web&lt;/b&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;b&gt;/location&lt;/b&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="para"&gt;Finally, you can write your own authorization logic by examining the user identity in your Web page code using the &lt;i&gt;Page.User&lt;/i&gt; property, which provides a &lt;i&gt;WindowsPrincipal&lt;/i&gt; object. You can retrieve the user name from the &lt;i&gt;WindowsPrincipal.Identity.Name&lt;/i&gt; property, and you can test group membership using the &lt;i&gt;WindowsPrincipal.IsInRole&lt;/i&gt; method. The following Web page code demonstrates these techniques:&lt;/div&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.Security.Principal;&lt;br /&gt;&lt;br /&gt;public class WindowsSecurityTest : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;protected System.Web.UI.WebControls.Label lblMessage;&lt;br /&gt;&lt;br /&gt;// (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;// Get the IIS-authenticated identity.&lt;br /&gt;WindowsIdentity identity = (WindowsIdentity)User.Identity;&lt;br /&gt;&lt;br /&gt;// Test if it is an Administrator.&lt;br /&gt;bool isAdmin = User.IsInRole(@"BUILTIN\Administrators");&lt;br /&gt;&lt;br /&gt;// Display some information about the identity.&lt;br /&gt;lblMessage.Text = "You have reached the secured page, " +&lt;br /&gt;User.Identity.Name + "." +&lt;br /&gt;"&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Authentication Type: " +&lt;br /&gt;identity.AuthenticationType.ToString() +&lt;br /&gt;"&amp;lt;br&amp;gt;Anonymous: " + identity.IsAnonymous.ToString() +&lt;br /&gt;"&amp;lt;br&amp;gt;Authenticated: " + identity.IsAuthenticated.ToString() +&lt;br /&gt;"&amp;lt;br&amp;gt;Guest: " + identity.IsGuest.ToString() +&lt;br /&gt;"&amp;lt;br&amp;gt;System: " + identity.IsSystem.ToString() +&lt;br /&gt;"&amp;lt;br&amp;gt;Administrator: " + isAdmin.ToString();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;&lt;/div&gt;&lt;div class="zoundry_raven_tags" xmlns=""&gt;Technorati : &lt;a class="ztag" href="http://www.technorati.com/tag/IIS+Authentication" rel="tag"&gt;IIS Authentication&lt;/a&gt; &lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-918014744348909189?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/918014744348909189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=918014744348909189' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/918014744348909189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/918014744348909189'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/using-iis-authentication.html' title='Using IIS Authentication'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-191216818351995633</id><published>2008-10-06T12:48:00.001+05:30</published><updated>2008-10-06T12:48:41.180+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Uploading a File'/><title type='text'>Allow User to Upload File</title><content type='html'>&lt;p class="first-para"&gt;Because ASP.NET executes on the server, there is no way to access any of the resources on the client computer, including files. However, you can use the &lt;em&gt;System.Web.UI.HtmlControls.HtmlInputFile&lt;/em&gt; control to allow a user to upload a file. This control renders itself as the HTML &amp;lt;&lt;em&gt;input type="file"&lt;/em&gt;&amp;gt; element, which is displayed as a Browse button and a text box that contains a filename. The user clicks the Browse button and chooses a file. This step takes place automatically and doesn't require any custom code. The user must then click another button (which you must create) to start the actual upload process.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;Before you can create a working file upload page, you need to take these steps:&lt;/p&gt;&lt;br /&gt;&lt;ul class="itemizedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;You must set the encoding type of the form to &lt;em&gt;multipart/form-data&lt;/em&gt;. To make this change, find the &amp;lt;&lt;em&gt;form&lt;/em&gt;&amp;gt; tag in your .aspx file and modify it as shown here:&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p class="para"&gt;&amp;lt;&lt;span style="COLOR: #000000"&gt;&lt;span class="fixed"&gt;form id="Form1"&lt;/span&gt;&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;&lt;strong&gt;&lt;span class="fixed"&gt;enctype="multipart/form-data"&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;&lt;span class="fixed"&gt;runat="server"&lt;/span&gt;&lt;/span&gt;&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;ul class="itemizedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;You need to add the &lt;em&gt;HtmlInputFile&lt;/em&gt; control. In Microsoft Visual Studio .NET, you'll find this control under the HTML tab of the Toolbox, with the name File Field. Once you've added this control, you must right-click it and choose Run As Server Control, which creates the required &amp;lt;&lt;em&gt;input type="file" runat="server"&lt;/em&gt;&amp;gt; tag.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;You must add another button that actually starts the file transfer using the specified file by calling the &lt;em&gt;HtmlInputFile.PostedFile.SaveAs&lt;/em&gt; method.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p class="para"&gt;&lt;a href="mk:@MSITStore:C:/Documents and Settings/admin/Desktop/BLOG s/CSharp Programmer's Cookbook.chm::/8351final/LiB0101.html#figure.Lib40" class="internaljump"&gt;Figure 7.3&lt;/a&gt; shows a sample page that allows file uploading. It includes an &lt;em&gt;HtmlInputFile&lt;/em&gt; control and uses the following code:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;public class UploadPage : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    protected System.Web.UI.WebControls.Label lblInfo;&lt;br /&gt;    protected System.Web.UI.WebControls.Button cmdUpload;&lt;br /&gt;    protected System.Web.UI.HtmlControls.HtmlInputFile FileInput;&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private void cmdUpload_Click(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;        if (FileInput.PostedFile.FileName == "") {&lt;br /&gt;&lt;br /&gt;            // No file was submitted.&lt;br /&gt;            lblInfo.Text = "No file specified.";&lt;br /&gt;&lt;br /&gt;}else {&lt;br /&gt;&lt;br /&gt;            try {&lt;br /&gt;&lt;br /&gt;                if (FileInput.PostedFile.ContentLength &amp;gt; 1048576) {&lt;br /&gt;&lt;br /&gt;                    // Forbid files larger than one megabyte.&lt;br /&gt;                    lblInfo.Text = "File is too large.";&lt;br /&gt;&lt;br /&gt;                }else {&lt;br /&gt;                    &lt;br /&gt;                    // The saved file will retain its original filename.&lt;br /&gt;                    string fileName = &lt;br /&gt;                      Path.GetFileName(FileInput.PostedFile.FileName);&lt;br /&gt;&lt;br /&gt;                    // The ASP.NET process must have rights for the location&lt;br /&gt;                    // where it is attempting to save the file, or an&lt;br /&gt;                    // "access denied" exception will occur.&lt;br /&gt;                    FileInput.PostedFile.SaveAs(fileName);&lt;br /&gt;                    lblInfo.Text = "File " + fileName + " uploaded.";&lt;br /&gt;                }&lt;br /&gt;            }catch (Exception err) {&lt;br /&gt;&lt;br /&gt;                lblInfo.Text = err.Message;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&lt;img src="http://img359.imageshack.us/img359/4333/asp1af2.jpg" alt="asp1.JPG" height="172" width="350"/&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;The code can check various properties of the submitted file, including its size, before saving it, which allows you to prevent a denial of service attack that tricks an ASP.NET application into filling the hard disk with large files. However, this code doesn't prevent a user from submitting the file in the first place, which can still slow down the server and be used to launch a different type of denial of service attack-one that works by tying up all free ASP.NET worker threads. To prevent this type of attack, use the &amp;lt;&lt;em&gt;httpruntime&lt;/em&gt;&amp;gt; tag in the Web.config file to specify a maximum file size. Specify the maximum, in kilobytes, using the &lt;em&gt;maxRequestLength&lt;/em&gt; attribute.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;br /&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;  &amp;lt;system.web&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;&lt;strong&gt;httpRuntime maxRequestLength="4096" /&lt;/strong&gt;&amp;gt;&lt;br /&gt;&amp;lt;!-- Other settings omitted. --&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;If you don't specify a maximum length, the default value of 4096 (4 megabytes) will apply. If the user attempts to submit a file that's too large, an exception will be thrown immediately when the page is posted back.&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Uploading+a+File" class="ztag" rel="tag"&gt;Uploading a File&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-191216818351995633?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/191216818351995633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=191216818351995633' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/191216818351995633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/191216818351995633'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/allow-user-to-upload-file.html' title='Allow User to Upload File'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-3444053068229123207</id><published>2008-10-06T12:45:00.001+05:30</published><updated>2008-10-06T12:45:33.464+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Setting Control Focus'/><title type='text'>Programmatically Set Control Focus</title><content type='html'>&lt;p class="first-para"&gt;The ASP.NET Web controls don't provide any way to programmatically set control focus. They do provide a &lt;em&gt;TabIndex&lt;/em&gt; property that allows you to set the tab order, but this property applies only to Microsoft Internet Explorer and can't be used to programmatically set the focus to the control of your choice. To overcome this limitation, you need to add a little snippet of JavaScript code.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The following subroutine generalizes this task. It accepts a reference to any control object, retrieves the associated client ID (which is the ID that the JavaScript code must use to refer to the control), and then builds and registers the startup script for setting the focus.&lt;/p&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;private void SetFocus(Control ctrl) {&lt;br /&gt;&lt;br /&gt;    // Define a JavaScript statement that will move focus to&lt;br /&gt;    // the desired control.&lt;br /&gt;    string setFocus = "&amp;lt;script language='javascript'&amp;gt;" +&lt;br /&gt;        "document.getElementById('" + ctrl.ClientID +&lt;br /&gt;        "').focus();&amp;lt;/script&amp;gt;";&lt;br /&gt;&lt;br /&gt;    // Add the JavaScript code to the page.&lt;br /&gt;    this.RegisterStartupScript("SetFocus", setFocus);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p class="para"&gt;If you add this subroutine to a Web form, you can call &lt;em&gt;SetFocus&lt;/em&gt; as needed. Here's an example that sets the focus when the page first loads:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;private void Page_Load(object sender,&lt;br /&gt;  System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;    if (!this.IsPostBack) {&lt;br /&gt;        // Move to a specific text box the first time the page loads.&lt;br /&gt;        SetFocus(TextBox1);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Setting+Control+Focus" class="ztag" rel="tag"&gt;Setting Control Focus&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-3444053068229123207?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/3444053068229123207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=3444053068229123207' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3444053068229123207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3444053068229123207'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/programmatically-set-control-focus.html' title='Programmatically Set Control Focus'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-5361259254618157865</id><published>2008-10-02T16:45:00.001+05:30</published><updated>2008-10-02T16:45:38.640+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET Pop up window'/><title type='text'>Pop-Up Window with JavaScript</title><content type='html'>&lt;p class="first-para"&gt;Because all ASP.NET code executes on the server, there is no way to show a new window from your C# page code. You can add URL hyperlinks to a page that will automatically open in a new window by setting the &lt;em&gt;target&lt;/em&gt; attribute of the &lt;em&gt;anchor&lt;/em&gt; tag to &lt;em&gt;_blank&lt;/em&gt;, but this still doesn't give you the ability to control the window size or style.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The solution is to use client-side JavaScript code to open the secondary window. The secondary window itself could be an HTML page, an ASP.NET page, an image file, or any other type of resource that can be opened in the client's browser. To open a secondary window, you use the &lt;em&gt;window.open&lt;/em&gt; function and specify three parameters. The first parameter is the link for the new page, the second is the frame name of the window, and the third is a comma- separated string of attributes that configure the style and size of the pop-up window. These attributes can include the following:&lt;/p&gt;&lt;br /&gt;&lt;ul class="itemizedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;The &lt;em&gt;height&lt;/em&gt; and &lt;em&gt;width&lt;/em&gt; attributes, which are set to pixel values.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;The &lt;em&gt;toolbar&lt;/em&gt;, &lt;em&gt;menuBar&lt;/em&gt;, and &lt;em&gt;scrollbars&lt;/em&gt; attributes, which can be set to yes or no depending on whether you want to display these elements.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;The &lt;em&gt;resizable&lt;/em&gt; attribute, which can be set to yes or no depending on whether you want a fixed or resizable window border.&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p class="para"&gt;The following example shows how you can configure an ASP.NET &lt;em&gt;Button&lt;/em&gt; so that it opens a second ASP.NET page in a pop-up window when clicked. Typically, you would add this code to the &lt;em&gt;Page.Load&lt;/em&gt; event handler.&lt;/p&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;string popupScript = "window.open('PopUp.aspx', " +&lt;br /&gt;  "'CustomPopUp', " +&lt;br /&gt;  "'width=200, height=200, menubar=yes, resizable=no')";&lt;br /&gt;&lt;br /&gt;cmdPopUp.Attributes.Add("onClick", popupScript);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p class="para"&gt;Here's the code you would use to show a pop-up window automatically when the page is displayed. This code would also go in the &lt;em&gt;Page.Load&lt;/em&gt; event handler.&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;string popupScript = "&amp;lt;script language='javascript'&amp;gt;" +&lt;br /&gt;  "window.open('PopUp.aspx', " +&lt;br /&gt;  "'CustomPopUp', " +&lt;br /&gt;  "'width=200, height=200, menubar=yes, resizable=no')" +&lt;br /&gt;  "&amp;lt;/script&amp;gt;";&lt;br /&gt;&lt;br /&gt;Page.RegisterStartupScript("PopupScript", popupScript);&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/ASP.NET+Pop+up+window" class="ztag" rel="tag"&gt;ASP.NET Pop up window&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5361259254618157865?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5361259254618157865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5361259254618157865' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5361259254618157865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5361259254618157865'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/pop-up-window-with-javascript.html' title='Pop-Up Window with JavaScript'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-5977400432594022897</id><published>2008-10-02T16:43:00.001+05:30</published><updated>2008-10-02T16:43:57.471+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET Client Side Events with JS'/><title type='text'>Respond to Client-Side Events with JavaScript</title><content type='html'>&lt;p class="first-para"&gt;ASP.NET includes a rich programming model. Unfortunately, once a page is rendered to HTML, you can't execute any more .NET code without first triggering a postback to the server. This limitation greatly reduces the effectiveness of validation code and other niceties that can support polished interactive Web pages.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;Of course, there's no reason that you can't mingle client-side JavaScript functionality with your .NET code. Although .NET doesn't include any object interface for creating JavaScript, you can manually inject it into the page. One way to do this is simply to set a control attribute. For example, you can create a text box that displays a message box when it loses focus by including the following JavaScript code:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;TextBox1.Attributes.Add("onBlur", "alert('The text box has lost focus!');");&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="para"&gt;The &lt;em&gt;TextBox&lt;/em&gt; tag will be rendered to HTML like this:&lt;/p&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&amp;lt;input name="TextBox1" type="text" id="TextBox1"&lt;br /&gt; onBlur="alert('The text box has lost focus!');"  ... /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p class="para"&gt;In this case, you're using the built-in JavaScript &lt;em&gt;alert&lt;/em&gt; function and the JavaScript &lt;em&gt;onBlur&lt;/em&gt; event, which fires when a control loses focus. Most HTML elements support a small number of events, and some of the most useful include the following:&lt;/p&gt;&lt;br /&gt;&lt;ul class="itemizedlist"&gt;&lt;br /&gt;&lt;li class="first-listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;&lt;strong&gt;&lt;em&gt;onFocus&lt;/em&gt;&lt;/strong&gt;Occurs when a control receives focus&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;&lt;strong&gt;&lt;em&gt;onBlur&lt;/em&gt;&lt;/strong&gt;Occurs when focus leaves a control&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;&lt;strong&gt;&lt;em&gt;onClick&lt;/em&gt;&lt;/strong&gt;Occurs when the user clicks a control&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;&lt;strong&gt;&lt;em&gt;onChange&lt;/em&gt;&lt;/strong&gt;Occurs when the user changes the value of certain controls&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class="listitem"&gt;&lt;br /&gt;&lt;p class="first-para"&gt;&lt;strong&gt;&lt;em&gt;onMouseOver&lt;/em&gt;&lt;/strong&gt;Occurs when the user moves the mouse pointer over a control&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p class="para"&gt;Another approach to adding JavaScript code is to define a JavaScript function in a .NET string variable and then to instruct ASP.NET to insert it into the rendered Web form where it can be used. If you follow this approach, any control can call the function in response to a JavaScript event.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The following example demonstrates this technique with a simple Web page that includes a table and an image. As the user moves the mouse over the cells in the table, two custom JavaScript functions are used, one that highlights the current cell and one that removes the highlight from the previous cell. In addition, the highlighting function changes the image URL depending on which table column is currently selected. If the user hovers the mouse over the first column, an animated GIF of a happy face is shown. If the user hovers the mouse over the second or third column, an animated GIF of a book with a flashing question mark is shown instead.&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;&lt;br /&gt;public class JavaScriptTest : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    protected System.Web.UI.WebControls.Table Table1;&lt;br /&gt;    protected System.Web.UI.WebControls.Image Image1;&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;        // Define the JavaScript functions.&lt;br /&gt;        string highlightScript = &lt;br /&gt;            "&amp;lt;script language=JavaScript&amp;gt; " +&lt;br /&gt;            "function HighlightCell(cell) {" +&lt;br /&gt;            "cell.bgColor = '#C0C0C0';" +&lt;br /&gt;            "if (cell.cellIndex == 0)"+&lt;br /&gt;            "{document.Form1.Image1.src='happy_animation.gif';}"+&lt;br /&gt;            "else {document.Form1.Image1.src='question_animation.gif';}" +&lt;br /&gt;            ";}" +&lt;br /&gt;            "&amp;lt;/script&amp;gt;";&lt;br /&gt;&lt;br /&gt;        string unhighlightScript = &lt;br /&gt;            "&amp;lt;script language=JavaScript&amp;gt; " +&lt;br /&gt;            "function UnHighlightCell(cell) {" +&lt;br /&gt;            "cell.bgColor = '#FFFFFF';" +&lt;br /&gt;            "}" +&lt;br /&gt;            "&amp;lt;/script&amp;gt;";&lt;br /&gt;&lt;br /&gt;        // Insert the function into the page (it will appear just after&lt;br /&gt;        // the &amp;lt;form runat=server&amp;gt; tag.&lt;br /&gt;        // Note that each script block is associated with a string name.&lt;br /&gt;        // This allows multiple controls to register the same script block,&lt;br /&gt;        // while ensuring it will only be rendered in the final page once.&lt;br /&gt;        if (!this.IsClientScriptBlockRegistered("Highlight")) {&lt;br /&gt;            Page.RegisterClientScriptBlock("Highlight", highlightScript);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        if (!this.IsClientScriptBlockRegistered("UnHighlight")) {&lt;br /&gt;            Page.RegisterClientScriptBlock("UnHighlight", unhighlightScript);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // Set the attributes of every cell in the table.&lt;br /&gt;        foreach (TableRow row in Table1.Rows) {&lt;br /&gt;&lt;br /&gt;            foreach (TableCell cell in row.Cells) {&lt;br /&gt;&lt;br /&gt;            cell.Attributes.Add("onMouseOver", "HighlightCell(this);");&lt;br /&gt;            cell.Attributes.Add("onMouseOut", "UnHighlightCell(this);");&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;&lt;img src="http://img223.imageshack.us/img223/9745/imagero5.jpg" alt="image.JPG" height="230" width="324"/&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/ASP.NET+Client+Side+Events+with+JS" class="ztag" rel="tag"&gt;ASP.NET Client Side Events with JS&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5977400432594022897?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5977400432594022897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5977400432594022897' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5977400432594022897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5977400432594022897'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/respond-to-client-side-events-with.html' title='Respond to Client-Side Events with JavaScript'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-7514905114558263829</id><published>2008-10-02T16:42:00.001+05:30</published><updated>2008-10-02T16:42:18.719+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET Stateful Page Member'/><title type='text'>Creating Stateful Page Member Variables</title><content type='html'>&lt;p class="first-para"&gt;ASP.NET provides several state mechanisms, as described in &lt;a href="http://aspdotnetslackers.blogspot.com/2008/10/storing-information-between-postbacsk.html"&gt;previous post&lt;/a&gt;. However, none of these can be used automatically-they all require manual code to serialize and retrieve information. You can add a layer of abstraction by performing this serialization and retrieval once. The rest of your code can then interact directly with the member variables.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;In order for this approach to work, you need to read variable values at the start of every postback. The &lt;em&gt;Page.Load&lt;/em&gt; event is an ideal choice for this code because it always fires before any other control events. You can use a &lt;em&gt;Page.Load&lt;/em&gt; event handler to pre-initialize all your variables. In addition, you need to store all variables before the page is sent to the user, after all processing is complete. In this case, you can respond to the &lt;em&gt;Page.PreRender&lt;/em&gt; event, which fires after all event handlers, just before the page is converted to HTML and sent to the client.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The following page shows an example of how you might persist one &lt;em&gt;Page&lt;/em&gt; member variable (named &lt;em&gt;memberValue&lt;/em&gt;).&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;&lt;br /&gt;public class StatefulMembers : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;    // (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;    private int memberValue = 0;&lt;br /&gt;&lt;br /&gt;    private void Page_Load(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;        // Reload all member variables.&lt;br /&gt;        if (ViewState["memberValue"] != null) {&lt;br /&gt;            memberValue = (int)ViewState["memberValue"];&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void StatefulMembers_PreRender(object sender, &lt;br /&gt;      System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;        // Save all member variables.&lt;br /&gt;        ViewState["memberValue"] = memberValue;&lt;br /&gt;&lt;br /&gt;        // Display value.&lt;br /&gt;        lblCurrent.Text = memberValue.ToString();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // (Other event handlers can now work with memberValue directly.)&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/ASP.NET+Stateful+Page+Member" class="ztag" rel="tag"&gt;ASP.NET Stateful Page Member&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7514905114558263829?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7514905114558263829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7514905114558263829' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7514905114558263829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7514905114558263829'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/creating-stateful-page-member-variables.html' title='Creating Stateful Page Member Variables'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6076625805527403877</id><published>2008-10-02T16:38:00.001+05:30</published><updated>2008-10-02T16:41:52.609+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET information Passing'/><title type='text'>Storing Information Between Postbacsk</title><content type='html'>&lt;div class="first-para"&gt;ASP.NET is a stateless programming model. Every time a postback is triggered, your code loads into memory, executes, and is released from memory. If you want to keep track of information after your code has finished processing, you must use some form of state management.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;ASP.NET provides several ways to store information, or state, between requests. The type of state you use determines how long the information will live, where it will be stored, and how secure it will be. The below table lists the various state options provided by ASP.NET. This table doesn't include the &lt;i&gt;Cache&lt;/i&gt; object, which provides temporary storage and is described in the &lt;a href="http://aspdotnetslackers.blogspot.com/2008/10/redirect-user-to-another-page.html"&gt;previous post&lt;/a&gt;. You can also use other, custom, approaches, such as hidden fields or a back-end database.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;&lt;/div&gt;&lt;table border="1" class="table" style="margin-left: 10px;"&gt;&lt;caption class="table-title"&gt;Table : Types of State Management&lt;/caption&gt; &lt;thead&gt;&lt;tr valign="top"&gt; &lt;th align="left" class="th" scope="col" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Type of State&lt;/div&gt;&lt;/th&gt; &lt;th align="left" class="th" scope="col" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Allowed Data&lt;/div&gt;&lt;/th&gt; &lt;th align="left" class="th" scope="col" width="20%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Storage Location&lt;/div&gt;&lt;/th&gt; &lt;th align="left" class="th" scope="col" width="25%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Lifetime&lt;/div&gt;&lt;/th&gt; &lt;th align="left" class="th" scope="col" width="24%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Security&lt;/div&gt;&lt;/th&gt; &lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;View State&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;All serializable .NET data types.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="20%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;A hidden field in the current Web page.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="25%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Lost when the user navigates to another page.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="24%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;By default, it's insecure. However, you can use page directives to enforce encryption and hashing to prevent data tampering.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Query String&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;String data only.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="20%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;The browser's URL string.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="25%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Lost when the user enters a new URL or closes the browser. However, it can be stored in a bookmark.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="24%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Clearly visible and easy for the user to modify.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Session State&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;All serializable .NET data types.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="20%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Server memory (can optionally be configured for an external process or database).&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="25%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Times out after a predefined period (usually 20 minutes, but this period can be altered globally or programmatically).&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="24%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Secure because data is never transmitted to the client.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Custom Cookies&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;String data only.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="20%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;The client's computer (in memory or a small text file, depending on its lifetime settings).&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="25%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Set by the programmer. Can be used in multiple pages and can persist between visits.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="24%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Insecure, and it can be modified by the user.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr valign="top"&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Application State&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="16%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;All serializable .NET data types.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="20%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Server memory.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="25%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;The lifetime of the application (typically, until the server is rebooted). Unlike other methods, application data is global to all users.&lt;/div&gt;&lt;/td&gt; &lt;td align="left" class="td" width="24%"&gt;&lt;br /&gt;&lt;div class="table-para"&gt;Secure because data is never transmitted to the client.&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;&lt;div class="para"&gt;The syntax for different data-storing methods is similar. Data is stored in a collection object and indexed using a string name.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;The below figurehows a Web page that performs a test of several different forms of session state. When the user clicks the Store Data button, a new &lt;i&gt;System.DateTime&lt;/i&gt; object is created and stored in page view state, session state, and a custom cookie. When the user clicks the Get Data button, this information is retrieved and displayed. Finally, the Clear Data button removes information from all types of state.&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;&lt;img alt="aspform.JPG" height="219" src="http://img524.imageshack.us/img524/6306/aspformmi4.jpg" width="311" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;Here's the page code:&lt;/div&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.SessionState;&lt;br /&gt;&lt;br /&gt;public class TestState : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;protected System.Web.UI.WebControls.Button cmdClear;&lt;br /&gt;protected System.Web.UI.WebControls.Button cmdStore;&lt;br /&gt;protected System.Web.UI.WebControls.Button cmdGetData;&lt;br /&gt;protected System.Web.UI.WebControls.Label lblData;&lt;br /&gt;&lt;br /&gt;// (Designer code omitted.)&lt;br /&gt;&lt;br /&gt;private void cmdStore_Click(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;// Create a test object.&lt;br /&gt;DateTime now = DateTime.Now;&lt;br /&gt;&lt;br /&gt;// Store the object in view state.&lt;br /&gt;ViewState["TestData"] = now;&lt;br /&gt;&lt;br /&gt;// Store the object in session state.&lt;br /&gt;Session["TestData"] = now;&lt;br /&gt;&lt;br /&gt;// Store the object in a cookie.&lt;br /&gt;// Check if the cookie already exists (named Recipe07-02).&lt;br /&gt;if (Request.Cookies["Recipe07-02"] == null) {&lt;br /&gt;&lt;br /&gt;// Create the cookie.&lt;br /&gt;HttpCookie cookie = new HttpCookie("Recipe07-02");&lt;br /&gt;&lt;br /&gt;// The cookie can only store string data.&lt;br /&gt;// It can store multiple values, each with a different key.&lt;br /&gt;cookie["TestData"] = now.ToString();&lt;br /&gt;&lt;br /&gt;// (You can modify additional Cookie properties to change&lt;br /&gt;//  the expiry date.)&lt;br /&gt;&lt;br /&gt;// Attach the cookie to the response.&lt;br /&gt;// It will be submitted with all future requests to this site&lt;br /&gt;// until it expires.&lt;br /&gt;Response.Cookies.Add(cookie);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void cmdGetData_Click(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;lblData.Text = "";&lt;br /&gt;&lt;br /&gt;// Check for information in view state.&lt;br /&gt;if (ViewState["TestData"] != null) {&lt;br /&gt;&lt;br /&gt;DateTime data = (DateTime)ViewState["TestData"];&lt;br /&gt;lblData.Text += "&amp;lt;b&amp;gt;View state data:&amp;lt;/b&amp;gt; " +&lt;br /&gt;data.ToString() + "&amp;lt;br&amp;gt;";&lt;br /&gt;&lt;br /&gt;}else {&lt;br /&gt;&lt;br /&gt;lblData.Text += "No view state data found.&amp;lt;br&amp;gt;";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Check for information in session state.&lt;br /&gt;if (Session["TestData"] != null) {&lt;br /&gt;&lt;br /&gt;DateTime data = (DateTime)Session["TestData"];&lt;br /&gt;lblData.Text += "&amp;lt;b&amp;gt;Session state data:&amp;lt;/b&amp;gt; " +&lt;br /&gt;data.ToString() + "&amp;lt;br&amp;gt;";&lt;br /&gt;&lt;br /&gt;}else {&lt;br /&gt;&lt;br /&gt;lblData.Text += "No session data found.&amp;lt;br&amp;gt;";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Check for information in a custom cookie.&lt;br /&gt;HttpCookie cookie = Request.Cookies["Recipe07-02"];&lt;br /&gt;if (cookie != null) {&lt;br /&gt;&lt;br /&gt;string cookieData = (string)cookie["TestData"];&lt;br /&gt;lblData.Text += "&amp;lt;b&amp;gt;Cookie data:&amp;lt;/b&amp;gt; " +&lt;br /&gt;cookieData + "&amp;lt;br&amp;gt;";&lt;br /&gt;&lt;br /&gt;}else {&lt;br /&gt;&lt;br /&gt;lblData.Text += "No cookie data found.&amp;lt;br&amp;gt;";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void cmdClear_Click(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;ViewState["TestData"] = null;&lt;br /&gt;Session["TestData"] = null;&lt;br /&gt;// (You can also use Session.Abandon to clear all session&lt;br /&gt;//  information.)&lt;br /&gt;&lt;br /&gt;// To clear a cookie you must replace it with&lt;br /&gt;// a cookie that has an expiration date that has already passed.&lt;br /&gt;HttpCookie cookie = new HttpCookie("Recipe07-02");&lt;br /&gt;cookie.Expires = DateTime.Now.AddDays(-1);&lt;br /&gt;Response.Cookies.Add(cookie);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="para"&gt;One type of state that this page doesn't demonstrate is the query string. The query string requires a page redirect and is ideal for transferring information from one page to another. To set information, you must redirect the user to a new page and add the query string arguments to the end of the URL. You can use the &lt;i&gt;HttpServerUtility.UrlEncode&lt;/i&gt; and &lt;i&gt;UrlDecode&lt;/i&gt; methods to ensure the string data is URL legal. This method properly escapes any special characters.&lt;/div&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;DateTime now = DateTime.Now;&lt;br /&gt;string data = Server.UrlEncode(now.ToString());&lt;br /&gt;Response.Redirect("newPage.aspx?TestData=" + data);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="para"&gt;To retrieve this information, you can use the &lt;i&gt;HttpResponse.QueryString&lt;/i&gt; collection:&lt;/div&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;// Check for information in the query string.&lt;br /&gt;if (Request.QueryString["TestData"] != null) {&lt;br /&gt;&lt;br /&gt;string data = Request.QueryString["TestData"];&lt;br /&gt;data = Server.UrlDecode(data);&lt;br /&gt;lblData.Text += "&amp;lt;b&amp;gt;Found query string data:&amp;lt;/b&amp;gt; " + data + "&amp;lt;br&amp;gt;";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="zoundry_raven_tags" xmlns=""&gt;&lt;br /&gt;&lt;br /&gt;Technorati : &lt;a class="ztag" href="http://www.technorati.com/tag/ASP.NET+information+Passing" rel="tag"&gt;ASP.NET information Passing&lt;/a&gt; &lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6076625805527403877?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6076625805527403877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6076625805527403877' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6076625805527403877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6076625805527403877'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/storing-information-between-postbacsk.html' title='Storing Information Between Postbacsk'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-2869030670799108380</id><published>2008-10-02T16:32:00.001+05:30</published><updated>2008-10-02T16:32:52.958+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET Redirecting User'/><title type='text'>Redirect the User to Another Page</title><content type='html'>&lt;p class="first-para"&gt;The easiest way to redirect a user from one Web page to another is to use the &lt;em&gt;HttpResponse.Redirect&lt;/em&gt; method and supply a new URL. You can access the current &lt;em&gt;HttpResponse&lt;/em&gt; object through the &lt;em&gt;HttpContext&lt;/em&gt; object or by using the &lt;em&gt;Reponse&lt;/em&gt; property of a &lt;em&gt;Page&lt;/em&gt; or a &lt;em&gt;Control&lt;/em&gt; object. Here's an example of an event handler that redirects the user in response to a button click:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;private void cmdRedirect_Click(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;    Response.Redirect("newpage.aspx");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="para"&gt;The &lt;em&gt;Redirect&lt;/em&gt; method works with relative URLs to resources in the same virtual directory, and with fully qualified URLs. URLs can point to other ASP.NET pages, other types of documents (such as HTML pages or images), and other Web servers.&lt;/p&gt;&lt;br /&gt;&lt;p class="para"&gt;The &lt;em&gt;Redirect&lt;/em&gt; method sends a redirect instruction to the browser. The browser then requests the new page. The result is that the browser has to make two roundtrips to the Web server, and the Web server has to handle an extra request. A more efficient option is available through the &lt;em&gt;HttpServerUtility.Transfer&lt;/em&gt; method, which transfers execution to a different ASP.NET page on the same Web server. Here's an example:&lt;/p&gt;&lt;br /&gt;&lt;div class="widecontent"&gt;&lt;br /&gt;&lt;pre class="programlisting"&gt;&lt;br /&gt;private void cmdRedirect_Click(object sender, System.EventArgs e) {&lt;br /&gt;&lt;br /&gt;    Server.Transfer("newpage.aspx");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="last-para"&gt;The &lt;em&gt;Transfer&lt;/em&gt; method doesn't require an extra trip to the client, but it won't work if you need to transfer execution to another server or another type of resource other than a Web form (including a classic ASP page).&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/ASP.NET+Redirecting+User" class="ztag" rel="tag"&gt;ASP.NET Redirecting User&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2869030670799108380?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2869030670799108380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2869030670799108380' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2869030670799108380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2869030670799108380'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/10/redirect-user-to-another-page.html' title='Redirect the User to Another Page'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-5906543014290870319</id><published>2008-09-29T14:07:00.001+05:30</published><updated>2008-09-29T14:07:31.454+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Displaying an Image from SQL Server'/><title type='text'>You can stream the binary data returned by SQL Server directly using the</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;You can stream the binary data returned by SQL Server directly using the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Response.BinaryWrite&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;method. Do this after retrieving the data from the database.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim connectionString as String = "Your connection string"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objConnection as New SqlConnection(connectionString)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim commandText as String = "SELECT Image FROM imageTable"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objCommand as New SqlCommand(commandText, objConnection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objReader as SqlDataReader&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objConnection.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objReader = objCommand.ExecuteReader()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If objReader.Read() Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.ContentType = "image/jpeg"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.BinaryWrite( CType(objReader("Image"), Byte()) )&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch exc as Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Write( exc.ToString() )&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Not objConnection Is Nothing Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If objConnection.State = ConnectionState.Open Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objConnection.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;End If&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;If Not objReader Is Nothing Then&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objReader.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;This code will display the contents of the first record in the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;imageTable&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. In the example&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;code, the &lt;font face="Courier" size="1"&gt;Image&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;field in the SQL Server contains the binary data that is written out with&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the &lt;font face="Courier" size="1"&gt;Response.BinaryWrite&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Response.ContentType&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;should be set to the appropriate MIME-type of the image&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that you are trying to display.This can be stored in the database as well and retrieved&lt;/p&gt;&lt;br /&gt;&lt;p&gt;along with the image data.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Displaying+an+Image+from+SQL+Server" class="ztag" rel="tag"&gt;Displaying an Image from SQL Server&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5906543014290870319?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5906543014290870319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5906543014290870319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5906543014290870319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5906543014290870319'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/you-can-stream-binary-data-returned-by.html' title='You can stream the binary data returned by SQL Server directly using the'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-1532598029186097088</id><published>2008-09-29T14:03:00.001+05:30</published><updated>2008-09-29T14:03:58.441+05:30</updated><title type='text'>Inserting an Image into SQL Server</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;You must properly set up the SQL Server database table to accept images, as well as provide&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;a way on your Web Form to upload an image and send it to the SQL Server.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The table that will store the image must utilize the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;image&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;data type on a column that&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;will store the image. In the following examples, the name of this column is called &lt;font face="Courier" size="1"&gt;Image&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In the .ASPX file:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;form enctype="multipart/form-data" runat="server"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;input id="ImageFile" runat="server" type="file" /&amp;gt;&amp;lt;p /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;asp:button runat="server" id="UploadButton" OnClick="UploadImage" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub UploadImage(sender As Object, e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim connectionString As String = "Enter your Connection String"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim imageStream As Stream = ImageFile.PostedFile.InputStream&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim byteData(ImageFile.PostedFile.ContentLength) As Byte&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objConn As New SqlClient.SqlConnection(ConnectionString)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim cmdText As String = "INSERT INTO sql_images(Image) VALUES(@image)"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objCommand As New SqlClient.SqlCommand(cmdText, objConn)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objParam As New SqlClient.SqlParameter("@image", SqlDbType.Image)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;imageStream.Read(byteData, 0, imageFile.PostedFile.ContentLength)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objParam.Value = byteData&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objCommand.Parameters.Add(objParam)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objConn.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objCommand.ExecuteNonQuery()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch exc as System.Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ErrorLabel.Text = exc.ToString()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objConn.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;imageStream.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Note that you must include the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;System.Data&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;namespace for this code to compile.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;form&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;tag has an additional attribute called&lt;/font&gt; &lt;font face="Courier" size="1"&gt;enctype&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.This attribute allows binary&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;data to be passed through the form (which is needed for the image).&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In the code, the submitted image file is broken into a byte array (&lt;font face="Courier" size="1"&gt;imgdata&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;) and then&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;used as the value of the &lt;font face="Courier" size="1"&gt;SqlParameter&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;that is passed in as the image (&lt;/font&gt;&lt;font face="Courier" size="1"&gt;imgparam&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;,&lt;/font&gt; &lt;font face="Courier" size="1"&gt;@image&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;).&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-1532598029186097088?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/1532598029186097088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=1532598029186097088' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1532598029186097088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1532598029186097088'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/inserting-image-into-sql-server.html' title='Inserting an Image into SQL Server'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-8885232650961274635</id><published>2008-09-29T14:02:00.001+05:30</published><updated>2008-09-29T14:02:26.522+05:30</updated><title type='text'>Executing a Stored Procedure with No Results Returned</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;' Set up the connection / command&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim connectionString as String = "server=.;database=Northwind;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trusted_Connection=true"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim connection As New SqlConnection(connectionString)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim command As New SqlCommand("IncrementDownloads", connection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;command.CommandType = CommandType.StoredProcedure&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Execute, but don't return any results&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;connection.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;command.ExecuteNonQuery()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;connection.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;There are many cases, especially when using stored procedures, where it is unnecessary&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;to return a result set from the database. In those cases, the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;SqlCommand&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;provides a simple&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;ExecuteNonQuery()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method that can be used to run the results on the database.This&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;method doesn't return a result set-if one is returned it's simply ignored.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This technique is also useful when executing non-&lt;font face="Courier" size="1"&gt;SELECT&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;SQL scripts, such as&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;UPDATE&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;,&lt;/font&gt; &lt;font face="Courier" size="1"&gt;INSERT&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, and&lt;/font&gt; &lt;font face="Courier" size="1"&gt;DELETE&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, where returning a result set serves no purpose.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;When working with a datareader, make sure to close the connection. Unlike a&lt;/p&gt;&lt;br /&gt;&lt;p&gt;dataset, the connection stays open until you close it.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-8885232650961274635?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/8885232650961274635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=8885232650961274635' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8885232650961274635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8885232650961274635'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/executing-stored-procedure-with-no.html' title='Executing a Stored Procedure with No Results Returned'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-7905352429199817878</id><published>2008-09-29T14:00:00.001+05:30</published><updated>2008-09-29T14:00:18.244+05:30</updated><title type='text'>Using a Tool to Create a Data Access Layer</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;There are quite a few data access code generators available for .NET, with widely varying&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;costs and feature sets.This example demonstrates LLBLGen, an open source data tier&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;generator that supports a wide array of options for the created files. It generates stored&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;procedures for insert, update, select, and delete for the tables selected, and then creates&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;VB or C# classes to call these procedures. It is available at&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;http://www.sd.nl/&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;software/&lt;font face="Bembo" size="2"&gt;.This section uses version 1.2, released in November 2002.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;To use LLBLGen, simply start the program and provide the connection information&lt;/p&gt;&lt;br /&gt;&lt;p&gt;for your database, as below figure shows.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://img519.imageshack.us/img519/7287/textboxkx7.jpg" alt="textbox.JPG" height="385" width="416"/&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Next, choose the tables and views for which you want to generate data access classes, as shown in below figure&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;img src="http://img519.imageshack.us/img519/9836/new1fv3.jpg" alt="new1.JPG" height="385" width="416"/&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Now, choose the options you want for your .NET classes, including naming conventions,&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;namespaces, language, and method of storing the connection string. Below figure shows the available options.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;img src="http://img519.imageshack.us/img519/8922/new2br1.jpg" alt="new2.JPG" height="385" width="416"/&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Do the same thing for the SQL procedures-pick which ones you want to generate, choose a common name prefix for them, and pick other options as described in below figure.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;img src="http://img519.imageshack.us/img519/7271/new3wb9.jpg" alt="new3.JPG" height="385" width="416"/&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Finally, generate the code! Choose the output paths for the .NET source files and the T-SQL script file, and watch as it generates your code for you.Below figure concludes this example, showing how a successful code generation should end.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;img src="http://img519.imageshack.us/img519/5629/new4qz0.jpg" alt="new4.JPG" height="385" width="416"/&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7905352429199817878?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7905352429199817878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7905352429199817878' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7905352429199817878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7905352429199817878'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/using-tool-to-create-data-access-layer.html' title='Using a Tool to Create a Data Access Layer'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-2589659885047317318</id><published>2008-09-29T13:53:00.001+05:30</published><updated>2008-09-29T13:53:42.255+05:30</updated><title type='text'>Using Microsoft’s Data Access Application</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The first step is to reference the data,&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;SQLClient&lt;/span&gt;&lt;font face="Bembo" size="2"&gt;, and data access application block&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;namespaces. Add the following statements to the top of your data access client&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;source file:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@ Page Language="VB" ClassName="Recipe1001vb" %&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;%@ import Namespace="System.Data" %&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;%@ import Namespace="System.Data.SqlClient" %&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;%@ import Namespace="Microsoft.ApplicationBlocks.Data" %&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;Next, you have to place the following code inside a method.&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Page_Load&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;will do fine for&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;this example:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim dataSet As DataSet&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'parameter value variables&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim beginningDate As string = "1/1/1996"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim endingDate As string = "12/31/1996"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim connectionString As string = _&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;"Integrated Security=yes;Initial Catalog=Northwind;Data Source=(local)"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim arParams(1) As SqlParameter&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;arParams(0) = New SqlParameter("@Beginning_Date", beginningDate)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;arParams(1) = New SqlParameter("@Ending_Date", endingDate)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;dataSet = SqlHelper.ExecuteDataset(connectionString, _&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;CommandType.StoredProcedure, "Employee Sales by Country", arParams)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'bind dataSet to a WebControl and call Page.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch exception As Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'An error occurred - were your connection string,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'stored procedure name and parameters correct?&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'you could display the error via a WebControl or throw an exception here&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub 'Page_Load&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;This is a simple example-it barely scratches the surface of data access application&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;block functionality.There's support for performing transactional updates and fetching&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;XML as well as data-readers and caching parameters for multiple calls to a given stored&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;procedure.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The &lt;font face="Courier" size="1"&gt;SqlHelper&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;object manages just about everything for you. In order to achieve the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;same result in ADO.NET, you would need &lt;font face="Courier" size="1"&gt;SqlConnection&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;,&lt;/font&gt; &lt;font face="Courier" size="1"&gt;SqlCommand&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, and&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;SqlDataAdapter&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;objects in addition to what you've declared here. Connection management&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;is improved as well because the &lt;font face="Courier" size="1"&gt;SqlConnection&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;is created internally to the object.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;There is no need you for to close the connection-the object handles closing the connection&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;as it goes out of scope.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally, take the opportunity to examine the source code for the application block.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;There are many examples of best practices in the source code that you might want to&lt;/p&gt;&lt;br /&gt;&lt;p&gt;apply to your own projects!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2589659885047317318?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2589659885047317318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2589659885047317318' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2589659885047317318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2589659885047317318'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/using-microsofts-data-access.html' title='Using Microsoft’s Data Access Application'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6349887204413835021</id><published>2008-09-27T16:32:00.003+05:30</published><updated>2008-09-28T00:05:37.444+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Connecting to ODBC DB'/><title type='text'>Connecting to an ODBC Datasource</title><content type='html'>&lt;div align="left"&gt;&lt;span style="font-family: Courier; font-size: 0.6em;"&gt;Dim connectString As string = "DSN=myDSN;Uid=user;Pwd=pass"&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;Dim myConn As Microsoft.Data.Odbc.OdbcConnection = _&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;New Microsoft.Data.Odbc.OdbcConnection( connectString )&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;Try&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;myConn.Open()&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;span style="font-family: Courier; font-size: xx-small;"&gt;'do something and then be sure to close the connection...&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family: Courier; font-size: xx-small;"&gt;Finally&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;If Not myConn Is Nothing Then&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;myConn.Close()&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;End If&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;End Try&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;b&gt;&lt;span style="font-family: Bembo-Bold;"&gt;Comments&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;span style="font-family: Bembo; font-size: x-small;"&gt;According to Carsten Thomsen, author of&lt;/span&gt; &lt;i&gt;&lt;span style="font-family: Bembo-Italic; font-size: x-small;"&gt;Database Programming in C#&lt;/span&gt;&lt;/i&gt;&lt;span style="font-family: Bembo; font-size: x-small;"&gt;:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;i&gt;&lt;span style="font-family: Bembo-Italic; font-size: x-small;"&gt;The OdbcConnection class, which uses the Platform Invoke feature, is roughly twice as fast for&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;standard applications than the OleDbConnection.The latter uses COM, which is chatty, and&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;hence has more server round-trips. So unless your application is shipping large amounts of data&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;(hundreds of thousands of rows or more) per data request, you should at least consider using&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;the &lt;span style="font-family: Courier-Oblique; font-size: xx-small;"&gt;OdbcConnection&lt;/span&gt; &lt;span style="font-family: Bembo-Italic; font-size: x-small;"&gt;class.&lt;/span&gt; &lt;span style="font-family: Courier-Oblique; font-size: xx-small;"&gt;SqlConnection&lt;/span&gt; &lt;span style="font-family: Bembo-Italic; font-size: x-small;"&gt;is roughly 20 percent faster than&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Courier-Oblique; font-size: xx-small;"&gt;OdbcConnection&lt;/span&gt;&lt;span style="font-family: Bembo-Italic; font-size: x-small;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="zoundry_raven_tags" xmlns=""&gt;&lt;br /&gt;&lt;br /&gt;Technorati : &lt;a class="ztag" href="http://www.technorati.com/tag/Connecting+to+ODBC+DB" rel="tag"&gt;Connecting to ODBC DB&lt;/a&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6349887204413835021?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6349887204413835021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6349887204413835021' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6349887204413835021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6349887204413835021'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/connecting-to-odbc-datasource.html' title='Connecting to an ODBC Datasource'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-4861603548983141537</id><published>2008-09-27T16:31:00.001+05:30</published><updated>2008-09-27T16:31:16.670+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Connecting to MySQL DB'/><title type='text'>Connecting to MySQL Database</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;You can use the OleDB provider that ships with the .NET Framework. In this case, your&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;code would look something like this:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Dim connectString As string = _&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;"Provider=MySQLProv;Data Source=mydb;User Id=user;Password=pass"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim myConn As System.Data.OleDb.OleDbConnection = _&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;New System.Data.OleDb.OleDbConnection( connectString )&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myConn.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;`dosomething and then be sure to close the connection...&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Not myConn Is Nothing Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myConn.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Another option is to use the MySQL data provider by eInfoDesigns (which I have only&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;minimally examined). In which case, your code would look like so:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Dim connectString As string = _&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;"Data Source=server;Database=mydb;User ID=user;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&lt;font face="Times New Roman"&gt;-&amp;gt;&lt;/font&gt;Password=pass;Command Logging=false"&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim myConn As eInfoDesigns.dbProvider.MySqlClient.MySqlConnection = _&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;New eInfoDesigns.dbProvider.MySqlClient.MySqlConnection( connectString )&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myConn.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'do something and then be sure to close the connection...&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Not myConn Is Nothing Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myConn.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;You can access most datasources with the OleDB data provider, although it's not the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;most efficient way to do so.You get better performance using a custom data provider&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;dedicated to that particular datasource. Although Microsoft does not support a custom&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MySQL data provider, third-party software vendors are beginning to supply these.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Connecting+to+MySQL+DB" class="ztag" rel="tag"&gt;Connecting to MySQL DB&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4861603548983141537?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4861603548983141537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4861603548983141537' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4861603548983141537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4861603548983141537'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/connecting-to-mysql-database.html' title='Connecting to MySQL Database'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-2549221514213386087</id><published>2008-09-27T16:28:00.001+05:30</published><updated>2008-09-27T16:28:15.500+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Connecting to MS Access DB'/><title type='text'>Connecting to a Microsoft Access Database</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;To connect to a Microsoft Access database, you must include the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;System.Data.OleDb&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;namespace because all the ASP.NET classes that are required to connect to datasources&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;through an OleDB connection are located in this namespace.The ASPX page looks as&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;follows:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;html&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;head&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;title&amp;gt;Connecting to a Microsoft Access Database&amp;lt;title&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/head&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;body&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;form runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;h3&amp;gt;Connecting to a Microsoft Access Database&amp;lt;/h3&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;p&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;asp:DataGrid id="dg1" runat="server"&amp;gt;&amp;lt;/asp:DataGrid&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/p&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;p&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;asp:Literal id="ltlError" runat="server"&amp;gt;&amp;lt;/asp:Literal&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/p&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;/html&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Add the following code within the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;tags:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Public Sub Page_Load(Source As Object, E As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim ConnectionString As String&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ConnectionString =&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &amp;amp; _&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Server.MapPath("Northwind.mdb") &amp;amp; ";"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim QuerySQL As String&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;QuerySQL = "SELECT * FROM Shippers"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objConn As New OleDbConnection(ConnectionString)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim objCmd As OleDbCommand&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objCmd = New OleDbCommand&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objCmd.CommandText = QuerySQL&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objCmd.Connection = objConn&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objConn.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;dg1.DataSource = objCmd.ExecuteReader()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;dg1.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch Err As Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ltlError.Text = Err.ToString()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;objConn.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;First, you must create a connection string that includes the driver and the source path of&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the source database. In this example, this has been assigned to the string type variable&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;named &lt;font face="Courier" size="1"&gt;ConnectionString&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. Remember that if you are using Microsoft Access 97, the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;connection string is going to be as follows:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;"Provider=Microsoft.Jet.OleDb.3.75;Data Source=" &amp;amp; _&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Server.MapPath("Northwind.mdb") &amp;amp; ";"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;Whereas when using Microsoft Access 2000 and XP, the string is as demonstrated in the&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;code.You must create the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Connection&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;and&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Command&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;objects as well.The Connection&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;object's constructor is provided with &lt;font face="Courier" size="1"&gt;ConnectionString&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, which contains the connection&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;string.The Command object's instance is assigned the query and the connection that it&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;will use to access the datasource.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Having established the basic settings for the Connection and the Command objects,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;you enclose the rest of the code within a &lt;font face="Courier" size="1"&gt;Try/Catch/Finally&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block to capture any type&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;of errors that arise. Afterwards, within the &lt;font face="Courier" size="1"&gt;Try/Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block, you open the connection&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;and call the &lt;font face="Courier" size="1"&gt;ExecuteReader&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method of the command object.This method executes the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;specified query text and returns the results to the DataGrid control that has been&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;assigned to it.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;When you view the page in the browser, you will see all the records from the database&lt;/p&gt;&lt;br /&gt;&lt;p&gt;table specified in the query.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Connecting+to+MS+Access+DB" class="ztag" rel="tag"&gt;Connecting to MS Access DB&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2549221514213386087?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2549221514213386087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2549221514213386087' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2549221514213386087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2549221514213386087'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/connecting-to-microsoft-access-database.html' title='Connecting to a Microsoft Access Database'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6174948622218793067</id><published>2008-09-27T16:26:00.001+05:30</published><updated>2008-09-27T16:26:23.810+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Connecting to Oracle'/><title type='text'>Connecting to Oracle</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Use the .NET data provider for Oracle, which is in the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;System.Data.OracleClient&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;namespace. This data provider does not come with .NET 1.0, but must be downloaded&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;separately. Working with Oracle connections is similar to working with SQL Server connections,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;as the following code demonstrates:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Dim connectString As string =&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;"Data Source=Oracle-Test;User ID=user;Password=pass"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim myConn As OracleConnection = New OracleConnection( connectString )&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;Try&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;myConn.Open()&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;//do something and then be sure to close the connection...&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Not myConn Is Nothing Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myConn.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;As with the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;SqlClient&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;data provider, the Oracle data provider offers significant performance&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;benefits over the OleDB connection method.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Connecting+to+Oracle" class="ztag" rel="tag"&gt;Connecting to Oracle&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6174948622218793067?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6174948622218793067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6174948622218793067' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6174948622218793067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6174948622218793067'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/connecting-to-oracle.html' title='Connecting to Oracle'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-4485443338841351442</id><published>2008-09-27T16:24:00.001+05:30</published><updated>2008-09-27T16:24:31.778+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Connecting to SQL Server'/><title type='text'>Connecting to SQL Server</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Use the SQL Server .NET data provider in the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;System.Data.SqlClient&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;namespace to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;connect to a Microsoft SQL Server 7.0 or 2000 database (for example, the Northwind&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sample database).Your connection strings can take advantage of integrated security or&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;connect using a given SQL login and password.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;First, you need to reference the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;SqlClient&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;namespace. Add the following statement&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;to the top of your data access client source file to reference the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;System.Data.SqlClient&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;namespace:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Imports System.Data.SqlClient&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Next, you need to create the connection, use it, and clean up inside a method. For&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;example, you can place the following in &lt;font face="Courier" size="1"&gt;Page_Load&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Dim connectString As string =&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;"Integrated Security=yes;Initial Catalog=Northwind;Data Source=(local)"&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim sqlConn As SqlConnection = New SqlConnection( connectString )&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sqlConn.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'do something and then be sure to close the connection...&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Not sqlConn Is Nothing Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sqlConn.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Here's an alternative version of an integrated security connection string.This will look&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;familiar if you build your connection strings using Universal Data Link (.UDL) files.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This VB.NET example explicitly references the Security Support Provider Interface&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;(SSPI) for the integrated security string and sets the connection string via the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;ConnectionString&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;property:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Dim sqlConn As SqlConnection = New SqlConnection()&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sqlConn.ConnectionString = "Integrated Security=SSPI;Initial&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;Catalog=Northwind;Data Source=(local)"&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sqlConn.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'do something and then be sure to close the connection...&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Not sqlConn Is Nothing Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sqlConn.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;As mentioned, you might also define a connection string that uses a specific SQL Server&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;logon ID. Using the first example, only the connection string changes:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;connectString =&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;"User ID=user;Password=pass;Initial Catalog=Northwind;Data Source=(local)"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Now, let's say you want to create a connection to a remote database server. In this case,&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;you need to specify the SQL Server logon ID and password again. Using the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;ConnectionString&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;property, the connection string will look similar to this:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;sqlConn.ConnectionString = "User ID=user;Password=pass;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Network Library=DBMSSOCN;Data Source=192.168.1.1,1433"&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Of course, you have to change the IP address to match your configuration.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The most important point to remember is this: if you open a connection you must&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;remember to close it.You cannot rely on ADO.NET's garbage collector to do it for you&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;in a timely manner. If you neglect to close your connections, you will likely run out of&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;available connections in short order! The best way to ensure that connections are properly&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;closed is to wrap their usage in &lt;font face="Courier" size="1"&gt;Try/Catch/Finally&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;blocks. Also, in addition to the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;techniques you've just seen, &lt;font face="Courier" size="1"&gt;SqlConnection&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;can also be created implicitly by certain&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;ADO.NET objects like the dataset.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Connecting+to+SQL+Server" class="ztag" rel="tag"&gt;Connecting to SQL Server&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4485443338841351442?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4485443338841351442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4485443338841351442' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4485443338841351442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4485443338841351442'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/connecting-to-sql-server.html' title='Connecting to SQL Server'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-3349077894119260379</id><published>2008-09-25T12:59:00.001+05:30</published><updated>2008-09-25T12:59:24.140+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Catching Exceptions in ASP.NET'/><title type='text'>Catching Exceptions</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Private Sub Page_Load(Source As Object, E As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _Connection As New&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;SqlConnection("Server=localhost;Database=pubs;uid=sa;pwd=;")&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _Command As New SqlCommand("Select * From Authors", _Connection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'_Connection.Open commented to cause an exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'_Connection.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataSource = _Command.ExecuteReader(CommandBehavior.CloseConnection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch _Error As Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MessageLabel.Text = _Error.Message&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_Connection.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;You can also provide multiple&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statements, as shown here:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Private Sub Page_Load(Source As Object, E As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'Error has been produced in the connection&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'string by writing "Server=localhos" (no 't')&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;Dim _Connection As New&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;SqlConnection("Server=localhos;Database=pubs;uid=sa;pwd=;")&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _Command As New SqlCommand("Select * From Authors", _Connection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_Connection.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataSource = _Command.ExecuteReader(CommandBehavior.CloseConnection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch _SqlError As SqlException&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MessageLabel.Text = _SqlError.Message&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch _Error As Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MessageLabel.Text= _Error.Message&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_Connection.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Try/Catch/Finally&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block is the best approach towards error handling. It provides a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;structured error-handling technique that was not available in previous versions of Visual&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Basic.The &lt;font face="Courier" size="1"&gt;Try&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block is provided with the code that is to be run.The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block is for&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;catching the exceptions raised by any line of code in the &lt;font face="Courier" size="1"&gt;Try&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block.The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Finally&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;is executed under both conditions-either when the &lt;font face="Courier" size="1"&gt;Try&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;section successfully executes or&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;when an error occurs and is passed to the &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block. It is for this reason that the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Close()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method of the connection object has been coded in the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Finally&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block, so as to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ensure that under both cases (whether successful or unsuccessful), the connection to the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;data store is closed.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Multiple &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statements can also be provided to capture different types of errors&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;raised by objects. In the second code listing, the exceptions that would be related to&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;SqlClient&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;objects are going to be captured by the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statement having an object of&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the &lt;font face="Courier" size="1"&gt;SqlException&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;class. All other exceptions are caught by the second catch statement&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;provided in the &lt;font face="Courier" size="1"&gt;Try&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The order of the &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statements is very important. Make sure you put the more&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;generalized &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;exceptions after the more specific exceptions. For example, in the second&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;code listing, &lt;font face="Courier" size="1"&gt;SqlException&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;is a subclass of&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Exception&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, and so is more specific.Thus,&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;its &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block occurs above the more generic exception's&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block. If the order&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;were reversed, the &lt;font face="Courier" size="1"&gt;SqlException Catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block would never be reached, because the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;exception block would always catch a &lt;font face="Courier" size="1"&gt;SqlException&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;that was thrown.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Catching+Exceptions+in+ASP.NET" class="ztag" rel="tag"&gt;Catching Exceptions in ASP.NET&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-3349077894119260379?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/3349077894119260379/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=3349077894119260379' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3349077894119260379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3349077894119260379'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/catching-exceptions.html' title='Catching Exceptions'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-344090885666017067</id><published>2008-09-25T12:57:00.001+05:30</published><updated>2008-09-25T12:57:42.891+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Handling Page Level Errors in ASP.NET'/><title type='text'>Handling Page Level Errors</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Page_Error()&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;event, exposed by the Page object, can be used to catch errors on a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;page level.The following code demonstrates how you can use this event for page level&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;error handling.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Private Sub Page_Load(Source As Object, E As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _Connection As New&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;SqlConnection("Server=localhost;Database=pubs;uid=sa;pwd=;")&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _Command As New SqlCommand("Select * From Authors", _Connection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'_Connection.Open() causes an exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataSource = _Command.ExecuteReader(CommandBehavior.CloseConnection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_Connection.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Public Sub Page_Error(Source As Object, E As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Write(Server.GetLastError.ToString())&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Server.ClearError()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The demonstrated code tries to execute a query without having an open connection to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the datasource.This raises an exception, which is captured by the &lt;font face="Courier" size="1"&gt;Page_Error()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;event of&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the Page object itself.Within the &lt;font face="Courier" size="1"&gt;Page_Error&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;event, the code displays the error message&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;by calling the &lt;font face="Courier" size="1"&gt;GetLastError&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method of the Server object.This returns an exception&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;object that is generated by the error. Note that the data access technique used in this&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;code is not a good approach for connecting to datasources; it has been adopted here&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;only for demonstrating the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Page_Error&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;event.You should always use the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Try/Catch/Finally&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statements for interacting with datasources.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Errors can also be handled at the application level using the &lt;font face="Courier" size="1"&gt;Application_Error&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;event found in global.asax.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Handling+Page+Level+Errors+in+ASP.NET" class="ztag" rel="tag"&gt;Handling Page Level Errors in ASP.NET&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-344090885666017067?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/344090885666017067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=344090885666017067' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/344090885666017067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/344090885666017067'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/handling-page-level-errors.html' title='Handling Page Level Errors'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-8038146953928022739</id><published>2008-09-25T12:55:00.001+05:30</published><updated>2008-09-25T12:55:40.470+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Raising Exceptions in ASP.NET'/><title type='text'>Raising Exceptions</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Private Sub Page_Load(Source As Object, E As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _Connection As New&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;SqlConnection("Server=localhost;Database=pubs;uid=sa;pwd=;")&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _Command As New SqlCommand("Select * From Authors", _Connection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_Connection.Open()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataSource = _Command.ExecuteReader(CommandBehavior.CloseConnection)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DG1.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch _Error As Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Throw New Exception("Whoops.... You've got an error in the code!")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_Connection.Close()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Throw&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statement here creates a new exception and raises it, replacing the original&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;exception object.The error message that will appear on the page in this case is the one&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that has been provided as an argument to the constructor of the &lt;font face="Courier" size="1"&gt;Exception&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;object.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The original error message can also be passed to the &lt;font face="Courier" size="1"&gt;Throw&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statement in order to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;show the details.You can achieve this by passing the &lt;font face="Courier" size="1"&gt;Exception&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;object as a second argument&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;to the constructor of the newly raised exception.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Catch _Error As Exception&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Throw New Exception("Whoops.... You 've got an error in the code!", _Error)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Your exception message has been replaced by the original one, but your exception message&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;still appears.Where? Check out the &lt;font face="Courier" size="1"&gt;Stack Trace&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;section.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Throw&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statement can be used to explicitly throw an exception or to rethrow a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;caught exception.The new exception being raised is provided with a customized statement,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;so as to hide error details and display a more simplified error message to the viewer.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;You can also pass along the original exception object to the raised exception.This can&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;be useful because it allows a friendly error message to be displayed to the user, but keeps&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;the detailed information for debugging purposes.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Raising+Exceptions+in+ASP.NET" class="ztag" rel="tag"&gt;Raising Exceptions in ASP.NET&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-8038146953928022739?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/8038146953928022739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=8038146953928022739' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8038146953928022739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8038146953928022739'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/raising-exceptions.html' title='Raising Exceptions'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-5080642876927169913</id><published>2008-09-25T12:53:00.001+05:30</published><updated>2008-09-25T12:53:52.719+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Page Level Tracing in ASP.NET'/><title type='text'>Enabling Page Level Tracing</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In order for page level tracing to be enabled, you need to add the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Trace&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;attribute to the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;@ Page directive.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@ Page Language="VB" Trace="true"%&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;The default value of the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Trace&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute is&lt;/font&gt; &lt;font face="Courier" size="1"&gt;false&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, which means that it is disabled. In&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;order to enable it, you simply set its value to&lt;/font&gt; &lt;font face="Courier" size="1"&gt;true&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. In&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Private Sub Page_Load(Source As Object, E As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trace.Write("Page_Load", "Declaring and initializing variables.")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _A As Integer = 10&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim _B As Integer = 20&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trace.Write("Page_Load", "Applying add operation.")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;_A += _B&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trace.Write("Page_Load", "Variable values changed.")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trace.Write("_A", _A)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trace.Write("_B", _B)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trace.Write &lt;font face="Bembo" size="2"&gt;can accept up to three arguments-the first one is the category for the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;message, the second is the actual message to display, and the third is the exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;information displayed after the message.The following listing demonstrates all three&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;arguments:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;...&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;...&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'code goes here&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch _Error As Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Trace.Write("Category", "Message", E)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In order to display&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Trace&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;messages from your code, use either the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Trace.Write()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;or the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Trace.Warn()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;statement.The difference between the two is that&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Trace.Warn&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;shows the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;output text in red, indicating a warning, whereas &lt;font face="Courier" size="1"&gt;Trace.Write()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;shows output in black&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;text. Both methods accept the same number and type of arguments.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;You can also use the &lt;font face="Courier" size="1"&gt;Trace.IsEnabled&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Boolean property to test whether tracing is&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;enabled prior to performing an expensive operation, such as looping through all values&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;on the page as part of a &lt;font face="Courier" size="1"&gt;Trace&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;output operation.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Note that to access tracing outside of a page, such as in a custom control, you must&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;refer to the current Web context by using &lt;font face="Courier" size="1"&gt;System.Web.HttpContext.Current.Trace()&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;instead of just&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Trace()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;or&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Page.Trace()&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Page+Level+Tracing+in+ASP.NET" class="ztag" rel="tag"&gt;Page Level Tracing in ASP.NET&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5080642876927169913?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5080642876927169913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5080642876927169913' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5080642876927169913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5080642876927169913'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/enabling-page-level-tracing.html' title='Enabling Page Level Tracing'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6610380138842835760</id><published>2008-09-24T12:24:00.001+05:30</published><updated>2008-09-24T12:24:57.047+05:30</updated><title type='text'>Logging Error Details</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Create an object of type&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;System.Diagnostics.EventLog&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;.Then begin the&lt;/span&gt; &lt;font face="Courier" size="1"&gt;try/catch&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;block and enter the code you suspect is causing the error. Create a&lt;/font&gt; &lt;font face="Courier" size="1"&gt;catch&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block to run if&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;an error occurs and assign the exception to the &lt;font face="Courier" size="1"&gt;ex&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;variable. Inside the block, create a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;new &lt;font face="Courier" size="1"&gt;EventLog&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;instance. Set the log to send the error to, and enter your application name&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;as the source. Finally, write the exception to the event log.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim a as Integer=0&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim myEventLog as System.Diagnostics.EventLog&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Try&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;a=1/a&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Catch ex as Exception&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog=new System.Diagnostics.EventLog()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog.Log="Application"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog.Source="Recipe0902"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog.WriteEntry(ex.ToString())&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;End Try&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;End Sub&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;You also can handle errors on an application error by modifying the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Application_Error&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;event handler in the global.asax file. Use&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Server.GetLastError()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;to get a reference to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the exception that was thrown.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In the global.asax file:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim myEventLog As System.Diagnostics.EventLog&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim ex As Exception = Server.GetLastError()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog = New System.Diagnostics.EventLog()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog.Log = "Application"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog.Source = "Recipe0902"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;myEventLog.WriteEntry(ex.ToString())&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Catching and keeping a log of errors that occur can greatly decrease the amount of time&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;you spend supporting an application. Note:The ASP.NET account does not have access&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;to write to the event log by default.To run this example, you need to do one of the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;following:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;1.&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Modify the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;processModel&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;element in&lt;/font&gt; &lt;font face="Courier" size="1"&gt;machine.config&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;to set ASP.NET to run as&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the System account.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;&lt;font size="1"&gt;2.&lt;/font&gt;Add the ASP.NET account to the local Administrators group.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;3.&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Use regedt32 to grant the ASP.NET account write access to the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;key.&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6610380138842835760?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6610380138842835760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6610380138842835760' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6610380138842835760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6610380138842835760'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/logging-error-details.html' title='Logging Error Details'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-7238782517342090470</id><published>2008-09-24T12:22:00.001+05:30</published><updated>2008-09-24T12:22:59.773+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Access'/><title type='text'>Configuring a Default Error Page in ASP.NET</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In the web.config file, locate the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;customErrors&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;section. Set the mode to on and set the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;URL for the default redirect.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The web.config file is as follows:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;customErrors mode="On" defaultRedirect="Recipe0901bvb.aspx"/&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim a as Integer=1/0&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The error handler page is as follows:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;html&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;body&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;form id="Recipe0901bvb" method="post" runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;An error has occurred in this application.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/body&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Whenever an unhandled error occurs anywhere in your application, the users are directed&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;to your custom error screen.This is an important part of creating a professional and&lt;/p&gt;&lt;br /&gt;&lt;p&gt;secure Web site. Note that the contents of the web.config file are case sensitive.&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Data+Access" class="ztag" rel="tag"&gt;Data Access&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7238782517342090470?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7238782517342090470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7238782517342090470' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7238782517342090470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7238782517342090470'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-default-error-page-in.html' title='Configuring a Default Error Page in ASP.NET'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-3234346462505135135</id><published>2008-09-22T22:47:00.001+05:30</published><updated>2008-09-22T22:47:58.954+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security - Custom Auth'/><title type='text'>Perform Custom Authentication on Each Request</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The application event,&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Application_AuthenticateRequest&lt;/span&gt;&lt;font face="Bembo" size="2"&gt;, which is defined in&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;global.asax, is used to perform custom authentication on every request to an application.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;It is the perfect place to add custom checks to determine whether the users should be&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;given access to a particular resource, or to determine which resources the user should be&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;able to access. In the following example, the list of roles the user belongs to is retrieved&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;and stored in the &lt;font face="Courier" size="1"&gt;HttpContext&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;collection, which is available for the life of each request.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Individual resources can then use the list to determine whether the users should have&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;access to them.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In global.asax (or its codebehind), do the following:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Application_AuthenticateRequest(ByVal sender As Object sender,&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;ByVal e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Request.IsAuthenticated = True Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim roles() As String&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' get this user's roles (left out)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' store roles in Context for the rest of this request&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Context.Items.Add("SecurityRoles", roles)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Security+-+Custom+Auth" class="ztag" rel="tag"&gt;Security - Custom Auth&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-3234346462505135135?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/3234346462505135135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=3234346462505135135' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3234346462505135135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3234346462505135135'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/perform-custom-authentication-on-each.html' title='Perform Custom Authentication on Each Request'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-5586017865164736715</id><published>2008-09-22T22:46:00.001+05:30</published><updated>2008-09-22T22:46:47.288+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security - Logout Form'/><title type='text'>Creating a Simple Forms Authentication Logout Page</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Place a LinkButton control on the page and assign it the text of&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Logout&lt;/span&gt;&lt;font face="Bembo" size="2"&gt;. Place a Literal&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;control on your page and title it message.This will be populated with a message telling&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the users they have logged out and including the code to redirect them to another page.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The ASPX page is as follows:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;p align="center"&amp;gt;&amp;lt;asp:LinkButton ID="Logout" Runat="server" OnClick="Logout_&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;Click"&amp;gt;Logout&amp;lt;/asp:LinkButton&amp;gt;&amp;lt;/p&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;p align="center"&amp;gt;&amp;lt;asp:Literal ID="Message" Runat="server" /&amp;gt;&amp;lt;/p&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;private void Logout_Click(object sender, System.EventArgs e)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;{&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;System.Web.Security.FormsAuthentication.SignOut();&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Message.Text="You have been logged out.";&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Message.Text+="&amp;lt;meta http-equiv=\"Refresh\"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;content=\"3;URL=http://aspalliance.com\" /&amp;gt;";&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;On the Logout button&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Click&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;event, do the following:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Call&lt;/font&gt; &lt;font face="Courier" size="1"&gt;System.Web.Security.FormsAuthentication.SignOut()&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.This method&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;forces a log out by removing the authentication ticket and session cookies.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Add text to the Message literal control to let the users know they have been&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;logged out.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Add a Meta tag to the Message literal control to redirect the users to another page.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If you want to send the users back to the login page, you can redirect them to any&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;page in the application. Forms authentication will force the users to log in first&lt;/p&gt;&lt;br /&gt;&lt;p&gt;(assuming the page requires an authenticated user).&lt;/p&gt;&lt;br /&gt;&lt;p xmlns="" class="zoundry_raven_tags"&gt;&lt;br /&gt;  &lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;&lt;br /&gt;  &lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/Security+-+Logout+Form" class="ztag" rel="tag"&gt;Security - Logout Form&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5586017865164736715?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5586017865164736715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5586017865164736715' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5586017865164736715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5586017865164736715'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-simple-forms-authentication_22.html' title='Creating a Simple Forms Authentication Logout Page'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-1759516011728601957</id><published>2008-09-22T22:44:00.001+05:30</published><updated>2008-09-22T22:44:11.205+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security - Login Form'/><title type='text'>Creating a Simple Forms Authentication Login Page</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Place two TextBox controls for the username and password on the page. Set the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;TextMode property of the password TextBox control to&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Password&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;. Add a Button control&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;to perform the login, and a Label control to provide feedback to the users.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;The ASPX page is as follows:&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;p align="center"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;table cellpadding="2" cellspacing="0" bgcolor="#fafade"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;th colspan="2" bgcolor="#baba99"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Login&amp;lt;/th&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;td&amp;gt;User Name:&amp;lt;/td&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;td&amp;gt;&amp;lt;asp:TextBox ID="UserName" Runat="server" /&amp;gt;&amp;lt;/td&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;td&amp;gt;Password:&amp;lt;/td&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;td&amp;gt;&amp;lt;asp:TextBox ID="Password" Runat="server"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;TextMode="Password" /&amp;gt;&amp;lt;/td&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;td colspan="2" align="center"&amp;gt;&amp;lt;asp:Button ID="Login"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Text="Login" Runat="server" OnClick="Login_Click"/&amp;gt;&amp;lt;/td&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/tr&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/table&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;br&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;asp:Label ID="Message" Runat="server" ForeColor="#FF0000"&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/p&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;block or codebehind:&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Private Sub Login_Click(sender as Object, e as System.EventArgs)&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;If UserName.Text="johndoe" AND Password.Text="password" Then&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;System.Web.Security.FormsAuthentication.RedirectFromLoginPage(&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: ZapfDingbats"&gt;➥&lt;/span&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;UserName.Text, False)&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Else&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Message.Text="Invalid Username/Password combination"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;On the Login button&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Click&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;event, you simply add code to verify the user ID and&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;password are correct.You will most likely want to query a database or check another&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;source to verify the password instead of hard coding the logins in your code. If the&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;password is correct, you call &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;System.Web.Security.FormsAuthentication.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;RedirectFromLoginPage &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;to send the users to the page they had originally requested.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Pass this function the name of the user who has logged in for use later in your application,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;and pass it a boolean of whether to persist the cookie across browser sessions (many&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;login forms use a check box to determine which value to use for this). If the password is&lt;/p&gt;&lt;br /&gt;&lt;p&gt;not correct, you display an error to the users.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-1759516011728601957?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/1759516011728601957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=1759516011728601957' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1759516011728601957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1759516011728601957'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-simple-forms-authentication.html' title='Creating a Simple Forms Authentication Login Page'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-2322396771800928346</id><published>2008-09-20T20:29:00.001+05:30</published><updated>2008-09-20T20:29:40.314+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security in ASP.NET'/><title type='text'>Requiring Authentication to Access Files and Folders</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Define separate location sections in the web.config file with unique authorization&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;settings:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;1. &amp;lt;location path="file"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;2.&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;location path="folder"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In the web.config file in Web application's root folder:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;authentication mode="Forms"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;forms name=".FormsCookie" loginUrl="Login.aspx" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/authentication&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;authorization&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;allow users="?,*" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/authorization&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;compilation defaultLanguage="VB" debug="true" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;location path="SpecialFile.aspx"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;authorization&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;deny users="?" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;allow users="*" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/authorization&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/location&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;location path="SpecialFolder"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;authorization&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;deny users="?" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;allow users="*" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/authorization&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/location&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Each sub-folder of the Web application can have its own web.config file that specifies its&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;authorization settings. Individual files however can only have unique authorization settings&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;specified with the use of the location section. Note that authentication, unlike&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;authorization, is an application-wide setting that cannot be overridden for files or&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;folders.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2322396771800928346?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2322396771800928346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2322396771800928346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2322396771800928346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2322396771800928346'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/requiring-authentication-to-access.html' title='Requiring Authentication to Access Files and Folders'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-1256538893487336087</id><published>2008-09-20T20:27:00.001+05:30</published><updated>2008-09-20T20:27:51.721+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security in ASP.NET'/><title type='text'>Configuring Windows Authentication</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Open the web.config file. Find the authentication tag under&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;system.web&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;and set the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;mode to &lt;font face="Courier" size="1"&gt;Windows&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.This is the default setting if you created the web.config file in Visual&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Studio.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The web.config file is as follows:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;system.web&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;authentication mode="Windows"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;You must also configure IIS to require authentication.To do this, follow these steps:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;1. Open Administrative Tools from either the Start menu or the Control Panel&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;(depending on the OS).&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;2. Open Internet Information Services.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;3. Branch out the tree to find your Web application folder.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;4. Right-click your Web application folder and choose Properties.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;5. Click the Director Security tab.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;6. Click the Edit button in the Authentication Control section.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;7. Uncheck the Anonymous Access box and make sure Integrated Authentication&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;(Challenge Response) option is checked.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;8. If you want to allow the users to type their passwords if IIS Challenge Response&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;fails, check Basic Authentication.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;9. Click both OK buttons and close IIS.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-1256538893487336087?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/1256538893487336087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=1256538893487336087' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1256538893487336087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1256538893487336087'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-windows-authentication.html' title='Configuring Windows Authentication'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6808157695694678892</id><published>2008-09-20T20:20:00.001+05:30</published><updated>2008-09-20T20:20:53.188+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security in ASP.NET'/><title type='text'>Configuring Forms Authentication</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The forms authentication setup process is done in the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;authentication&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;part of your&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;web.config file. As with all XML documents, the web.config file's contents are case&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sensitive.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Here's the application's web.config file:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;authentication mode="Forms"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;forms name="CookBookForm"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;loginUrl="login.aspx"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;protection="All"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;timeout="30"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier" size="1"&gt;path="/" /&amp;gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;/authentication&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;forms&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;tag in web.config provides all the configuration necessary to provide forms&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;authentication for your application.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This tag includes the following options:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Courier" size="1"&gt;name&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-This sets the name of the HTTP cookie that will be sent. If you have multiple&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;applications on the same server with forms authentication set up, you must&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;make this value unique in each one of them.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Courier" size="1"&gt;loginUrl&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-This sets the location where the users are redirected for login (or any&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;other action) if they are not authenticated and try to access a secure page.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Courier" size="1"&gt;protection&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-This specifies the level of protection to place on the cookie.You&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;can set this to All, None, Encryption or Validation, the default (and recommended)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;is All.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Courier" size="1"&gt;timeout&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-This sets the amount of time (in minutes) that a cookie remains valid,&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;after it was last requested, before it expires.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Courier" size="1"&gt;path&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-This sets the path for the cookies to use; default is a backslash.This provides&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;additional protection because the client browser will not send the cookie if&lt;/p&gt;&lt;br /&gt;&lt;p&gt;there is a path mismatch.This value is case-sensitive to some browsers.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6808157695694678892?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6808157695694678892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6808157695694678892' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6808157695694678892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6808157695694678892'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-forms-authentication.html' title='Configuring Forms Authentication'/><author><name>Sunita</name><uri>http://www.blogger.com/profile/09126980747092182401</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-7926983505765515035.post-6837177510387788565</id><published>2008-09-18T21:04:00.001+05:30</published><updated>2008-09-18T21:04:54.429+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ViewState'/><title type='text'>Reading and Storing Data in ViewState</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The ViewState collection provides an easy way to maintain values on a particular Web&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Form across postbacks.This collection is stored as a hidden form field, and thus all data&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;stored in ViewState is passed to and from the client on every request.You access it using&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;syntax similar to what you have seen for the Session and Application collections:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;ViewState("UserName")="UserNameTextBox.Text"&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;UserNameLabel.Text = ViewState("UserName")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;By default,Web controls that do not post back values will maintain their state automatically&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;using ViewState.This can be controlled individually for each control or globally for&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;each page by setting&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;EnableViewState&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;to&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;true&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;or&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;false&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;as desired (either for a given&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;control or in the page directive).The amount of space a control occupies in ViewState&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;can easily be determined from the control tree section of the trace output.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6837177510387788565?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6837177510387788565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6837177510387788565' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6837177510387788565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6837177510387788565'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/reading-and-storing-data-in-viewstate.html' title='Reading and Storing Data in ViewState'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-454524744072589</id><published>2008-09-18T20:49:00.001+05:30</published><updated>2008-09-18T20:49:31.223+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cookies'/><title type='text'>Reading and Storing Data in Cookies</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;You can store small pieces of user-specific information in the user's Cookies collection&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;on the user's local machine, assuming the local browser supports cookies and the user has&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;not disabled this feature.You can use cookies to hold data for as long as the current&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;browser window is open, or you can give them an expiration date some time in the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;future.The first variety is called an in-memory cookie, because they are never written to&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the user's hard drive.The second variety is referred to as a persistent cookie, because&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;these cookies persist across browser and even machine restarts.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;There are several ways to work with cookies in ASP.NET.The simplest uses syntax&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;very similar to that used for the Application and Session collections:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;'write a cookie&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cookies("UserName").Value = UserNameTextBox.Text&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'read a cookie&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;UserNameLabel.Text = Request.Cookies("UserName").Value&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In addition, you can give the cookies an expiration date, which will cause them to be&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;persisted to the user's hard drive.To delete these (and other) cookies, simply set their&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;expire date to any past date, as shown:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;'persist a cookie&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cookies("UserName").Expires =&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: ZapfDingbats"&gt;➥&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;System.DateTime.Now.AddDays(1) ' persist for 1 day&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;'delete a cookie&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Response.Cookies("UserName").Expires = System.DateTime.Now.AddDays(-1)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Cookies can be a great place to store small pieces of data that are needed from page to&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;page.They do not have the overhead of sessions, and they can span multiple user visits&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;over large time periods.They can also span applications within the same domain (for&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;example, &lt;font face="Courier" size="1"&gt;yahoo.com&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;). Not all users will accept cookies, however. It's best to test for this&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;by writing a test cookie and attempting to read it back on a subsequent request. Cookies&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;can store only small amounts of text data, with an upper limit of less than 4KB, which&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;includes the data and the keys used to extract the data (for example, &lt;font face="Courier" size="1"&gt;UserName&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;in the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;previous example).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-454524744072589?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/454524744072589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=454524744072589' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/454524744072589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/454524744072589'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/reading-and-storing-data-in-cookies.html' title='Reading and Storing Data in Cookies'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-4942077999809055972</id><published>2008-09-18T20:48:00.001+05:30</published><updated>2008-09-18T20:48:17.346+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Session Object'/><title type='text'>Reading and Writing Values to the Session Object</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;You can store user-specific information, such as a user's name, in the Session collection.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Because the Session collection is user specific, it should not be written to by multiple&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;threads concurrently.Therefore, you do not need to use locks around your writes, as you&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;must with the Application collection . Otherwise, the syntax is similar:&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Session("UserName")=UserNameTextBox.Text&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;UserNameLabel.Text = Session("UserName")&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;By default, the Session collection holds data for 20 minutes after the last request to an&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;application by a particular user.You can adjust this time period in the application's con-&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;figuration . Because data stored in sessions can grow linearly with the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;number of users, and because it persists for quite some time after each user leaves, it can&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;quickly impede scalability if it is used to store large amounts of data. It should therefore&lt;/p&gt;&lt;br /&gt;&lt;p&gt;be used sparingly.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4942077999809055972?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4942077999809055972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4942077999809055972' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4942077999809055972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4942077999809055972'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/reading-and-writing-values-to-session.html' title='Reading and Writing Values to the Session Object'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-8085835907999273479</id><published>2008-09-18T20:43:00.001+05:30</published><updated>2008-09-18T20:43:57.387+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='State Management'/><title type='text'>Reading and Writing Values to the Application Object</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;You can store the name of the server in application state using&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Application("ServerName") ="WebFarm1"&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;.You can retrieve it and display its value by&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;using &lt;font face="Courier" size="1"&gt;MyLabel.Text=Application("ServerName").ToString()&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. Because it returns the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;server name as an object, you need to convert it to a string using the &lt;font face="Courier" size="1"&gt;.ToString()&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;method before assigning it to&lt;/font&gt; &lt;font face="Courier" size="1"&gt;MyLabel.Text&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.The ASPX page is as follows:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;html&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;body&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;form id="Recipe0701vb" method="post" runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;asp:Label ID="MyLabel" Runat="server"/&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/body&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Application.Lock()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Application("ServerName")="WebFarm1"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Application.UnLock()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MyLabel.Text=Application("ServerName").ToString()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Application state is useful for storing values that you need to access throughout your&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;application. Once a value is added to application state, it exists for the life of the application.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Because multiple pages can attempt to write to the Application collection simultaneously,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;it must be locked using &lt;font face="Courier" size="1"&gt;Application.Lock&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;prior to any writes.The lock is&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;released using &lt;font face="Courier" size="1"&gt;Application.UnLock&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.The only time locking isn't necessary is in code&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that isn't executed by multiple page requests, such as in &lt;font face="Courier" size="1"&gt;Application_Start&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;in the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;global.asax.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-8085835907999273479?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/8085835907999273479/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=8085835907999273479' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8085835907999273479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8085835907999273479'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/reading-and-writing-values-to.html' title='Reading and Writing Values to the Application Object'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-1980123442816573795</id><published>2008-09-18T20:25:00.001+05:30</published><updated>2008-09-18T20:25:44.986+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sessions'/><title type='text'>Configuring Sessions in your ASP.NET Application</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;All of the configuration is provided by the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;sessionState&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;element in the web.config&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;file; all you have to do is alter the appropriate attributes.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;There are several ways to store session information; these are described next.To disable&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Session&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;state, add this to web.config:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;sessionState mode="Off"/&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;To enable local storage of&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Session&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;state, add this to web.config:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;sessionState mode="InProc"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;cookieless="true"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;timeout="10" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;InProc&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;setting sets it so that the information is stored locally (the default).&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Cookieless&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;can be set to&lt;/font&gt; &lt;font face="Courier" size="1"&gt;true&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;or&lt;/font&gt; &lt;font face="Courier" size="1"&gt;false&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;and tells ASP.NET whether to use cookies&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;when storing session information. &lt;font face="Courier" size="1"&gt;Timeout&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;sets the time in minutes that sessions will&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;expire if they remain unused.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;To enable storage of &lt;font face="Courier" size="1"&gt;Sessions&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;on a state server add this to web.config:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;sessionState mode="StateServer"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;stateConnectionString="tcpip=127.0.0.1:42424" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;This tells ASP.NET to use a state server at the specified address (&lt;/font&gt;&lt;font face="Courier" size="1"&gt;stateConnectionString&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;).&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The state server is found at &lt;font face="Courier" size="1"&gt;%SYSTEMROOT%\Microsoft.NET\Framework\&lt;/font&gt;&lt;em&gt;&lt;font face="Courier-Oblique" size="1"&gt;version&lt;/font&gt;&lt;/em&gt;&lt;font face="Courier" size="1"&gt;\&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;aspnet_state.exe&lt;font face="Bembo" size="2"&gt;.This server then listens on port 42424 over TCP/IP; you can use&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;this port to store your session information.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;To enable storage of &lt;font face="Courier" size="1"&gt;Sessions&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;on a SQL Server, add this to web.config:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;sessionState mode="SQLServer"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;sqlConnectionString="data source=localhost;user id=sa;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="ZapfDingbats" size="1"&gt;➥&lt;/font&gt;&lt;font face="Courier" size="1"&gt;password=securepassword;" /&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;This method tells ASP.NET to use SQL Server to store the information.To set up a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;SQL Server to store session information, you must run the InstallSqlState.sql file located&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;in&lt;/font&gt; &lt;font face="Courier" size="1"&gt;%SYSTEMROOT%\Microsoft.NET\Framework\&lt;/font&gt;&lt;em&gt;&lt;font face="Courier-Oblique" size="1"&gt;version&lt;/font&gt;&lt;/em&gt;&lt;font face="Courier" size="1"&gt;\&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;on the SQL Server (there is an&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;UninstallSqlState.sql file to uninstall it as well).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-1980123442816573795?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/1980123442816573795/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=1980123442816573795' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1980123442816573795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1980123442816573795'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-sessions-in-your-aspnet.html' title='Configuring Sessions in your ASP.NET Application'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-4582297614984444726</id><published>2008-09-18T20:15:00.001+05:30</published><updated>2008-09-18T20:15:52.500+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Application Error Handling'/><title type='text'>Configuring Application Error Handling</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The web.config file includes a&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;customErrors ...&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;section that controls how the application&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;responds to errors on its pages. A typical &lt;font face="Courier" size="1"&gt;customErrors&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;section follows:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;customErrors mode="RemoteOnly" defaultRedirect="/Maintenance.aspx" &amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;error statusCode="404" redirect="/NotFound.aspx" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/customErrors&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The settings are case-sensitive.The first attribute,&lt;/font&gt; &lt;font face="Courier" size="1"&gt;mode&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, can be&lt;/font&gt; &lt;font face="Courier" size="1"&gt;On&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;,&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Off&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, or&lt;/font&gt; &lt;font face="Courier" size="1"&gt;RemoteOnly&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The first two are self-explanatory; the third redirects errors only for non-local users, so&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that a local developer can still debug problems without being routed to the "friendly"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;error page.The second attribute, &lt;font face="Courier" size="1"&gt;defaultRedirect&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, specifies the page to which any&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;request that results in an unhandled exception is sent. If it is not set but custom errors&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;are on, users will see a generic error message (instead of the detailed exception information).&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Optionally, specific redirects can be set up for individual error codes by adding&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;error ...&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;elements within the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;customErrors&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;element. Each of these can specify a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;statusCode&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, such as 404, that maps to a file not found error code, or 500, for a generic&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;application error. Each error code can be mapped to its own specific error page by setting&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the path to the page in the redirect attribute.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Setting up friendly default error pages for ASP.NET applications and their common&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;errors is fairly straightforward. It is useful to have the default error page write to a log&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;with details of the request or URL that caused the problem. It can also be useful to log&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;which files users are requesting that are resulting in 404s, and ideally to have the 404&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;error page automatically redirect users to new locations of old resources.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Note, however, that these error pages handle requests only for resources that the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ASP.NET engine is registered to handle. So a request for a missing .ASPX file would&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;result in the 404 page being called, but by default a request for a nonexistent .HTM or&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;.GIF file would not. Additional file types can be associated with the ASP.NET process in&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;IIS, but this imposes a performance penalty. Note that most of this functionality is also&lt;/p&gt;&lt;br /&gt;&lt;p&gt;available within IIS.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4582297614984444726?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4582297614984444726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4582297614984444726' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4582297614984444726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4582297614984444726'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-application-error-handling.html' title='Configuring Application Error Handling'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-4505201294693223564</id><published>2008-09-18T20:10:00.001+05:30</published><updated>2008-09-18T20:10:12.391+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Application Debugging'/><title type='text'>Configuring Application Debugging</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The web.config file includes a&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;compilation ...&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;section that sets whether debug&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;mode is set for an ASP.NET application. A typical compilation section follows:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;compilation&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;defaultLanguage="vb"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;debug="true"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;/&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Setting&lt;/font&gt; &lt;font face="Courier" size="1"&gt;debug="true"&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;(which is case-sensitive) enables debug mode for your application.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This means the .PDB file for your assembly will be copied to the application's &lt;font face="Courier" size="1"&gt;/bin&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;folder, which means detailed debug information (stack trace, line numbers, and so on)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;will be provided in response to exceptions. Note that there is a significant performance&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;penalty to application running in debug mode. Individual pages can also be set up to run&lt;/p&gt;&lt;br /&gt;&lt;p&gt;in debug mode by setting &lt;font face="Courier" size="1"&gt;debug="true"&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;in the individual page directive.&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4505201294693223564?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4505201294693223564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4505201294693223564' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4505201294693223564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4505201294693223564'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-application-debugging.html' title='Configuring Application Debugging'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-2324758322486539688</id><published>2008-09-18T20:08:00.001+05:30</published><updated>2008-09-18T20:08:53.818+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tracing'/><title type='text'>Configuring Application Tracing</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The web.config file includes a&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;trace ...&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;section that is used to set up tracing options&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;for an ASP.NET application. A typical trace section follows:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;trace&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;enabled="false"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;requestLimit="10"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;pageOutput="false"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;traceMode="SortByTime"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;localOnly="true"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;/&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;This example demonstrates all of the fields available to modify application tracing.The&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;first field controls whether tracing is enabled.This defaults to &lt;font face="Courier" size="1"&gt;false&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;and can be overridden&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;at the individual page level.The second item, &lt;font face="Courier" size="1"&gt;requestLimit&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, controls how many&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;requests' trace results should be stored on the server. Once filled, this queue will not&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;accept new entries until the queue is deleted (which can be done from the trace.axd&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;page).The third attribute, &lt;font face="Courier" size="1"&gt;pageOutput&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, controls whether trace output should be displayed&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;on every page in the application.When set to &lt;font face="Courier" size="1"&gt;false&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, trace output is available only from&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the trace.axd URL (for example, &lt;font face="Courier" size="1"&gt;http://mydomain/myapplication/trace.axd&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;).&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Individual pages can override this setting by explicitly setting &lt;font face="Courier" size="1"&gt;trace="true"&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;or&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;trace="false"&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;in their page directive.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The fourth attribute, &lt;font face="Courier" size="1"&gt;traceMode&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, simply controls the ordering of the trace messages in&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the Trace Information section of the trace output.The allowable options are &lt;font face="Courier" size="1"&gt;SortByTime&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;(the default) and&lt;/font&gt; &lt;font face="Courier" size="1"&gt;SortByCategory&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. Finally, the last attribute,&lt;/font&gt; &lt;font face="Courier" size="1"&gt;localOnly&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, enables application&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;tracing only for requests originating from the local machine when set to &lt;font face="Courier" size="1"&gt;true&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;. Note&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that these items are case-sensitive.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Tracing can provide a powerful way to debug applications. By using the trace.axd URL&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;for trace output, developers can pull important details about a production ASP.NET&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;application without interfering with current users. However, be careful that you do not&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;place sensitive information in trace statements or collections that are exposed by the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;trace output (Application, Session, Forms, Cookies, QueryString, and so on), because by&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;default anybody can access the trace.axd URL and access this data. Note that you can&lt;/p&gt;&lt;br /&gt;&lt;p&gt;change the name of the trace.axd file by changing its name in the machine.config file.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2324758322486539688?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2324758322486539688/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2324758322486539688' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2324758322486539688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2324758322486539688'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-application-tracing.html' title='Configuring Application Tracing'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-696321116336006645</id><published>2008-09-18T20:06:00.001+05:30</published><updated>2008-09-18T20:06:48.361+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='web.config File - Custom Application Settings'/><title type='text'>Creating Custom Application Settings in the web.config File</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The web.config file has a predefined section for application settings, called&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;appSettings&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;.This section can be placed in any .config file, and must reside with the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;section.The following is an example of a simple web.config file:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;appSettings&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;add key="PageSize" value="25" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/appSettings&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Values can be retrieved using the Configuration API. However, all values are returned as&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;string types:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Dim pageSize As Integer&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;pageSize = CType(ConfigurationSettings.ApplicationSettings("PageSize"),&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Integer)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Storing common values within configuration, such as database connection strings, is a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;common feature that many applications take advantage of. Requiring developers to&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;write customer configuration section handlers to store simple values is overkill; hence&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the existence of the &lt;font face="Courier" size="1"&gt;&amp;lt;appSettings/&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;section.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Any simple data that you need stored in a central location and that must be available&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;anywhere within your Web application is a good candidate for the &lt;font face="Courier" size="1"&gt;&amp;lt;appSettings/&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;section. For other more complicated configuration data structures, you'll probably want&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;to create a custom configuration section handler.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-696321116336006645?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/696321116336006645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=696321116336006645' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/696321116336006645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/696321116336006645'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-custom-application-settings-in.html' title='Creating Custom Application Settings in the web.config File'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-6768644085119813044</id><published>2008-09-18T20:03:00.001+05:30</published><updated>2008-09-18T20:03:09.645+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='web.config - Custom Settings'/><title type='text'>Storing and Reading Custom Settings from the web.config File</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;ASP.NET provides two ways to store information within the configuration file.The first&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;is to store simple name/value settings within an&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;appSettings /&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;section,&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;The second is to create a custom configuration section that can store data&lt;/p&gt;&lt;br /&gt;&lt;p&gt;in any format.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In order to implement a custom configuration section handler, you must implement a&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;custom class that implements &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;IConfigurationSectionHandler&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;.The following is a partial&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;code sample for the new configuration section handler used for the ASP.NET&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;forums:&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Imports System&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Imports System.Collections&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Imports System.Collections.Specialized&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Imports System.Xml&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Imports System.Configuration&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Imports System.Web.Configuration&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Namespace AspNetForums.Configuration&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' *********************************************************************&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' ForumsConfigurationHandler&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;'&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Class used by ASP.NET Configuration to load ASP.NET Forums configuration.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' ***********************************************************************/&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Class ForumsConfigurationHandler&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Implements IConfigurationSectionHandler&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Public Overridable Overloads Function Create(ByVal parent As Object,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: ZapfDingbats"&gt;➥&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;ByVal configContext As Object, ByVal node As XmlNode) As Object&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: ZapfDingbats"&gt;➥&lt;/span&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Implements IConfigurationSectionHandler.Create&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Dim config As New ForumConfiguration(CType(parent,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;ForumConfiguration))&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;config.LoadValuesFromConfigurationXml(node)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Return config&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Function&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Class&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' *********************************************************************&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' ForumConfiguration&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;'&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Class used to represent the configuration data for the ASP.NET Forums&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' ***********************************************************************/&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Public Class ForumConfiguration&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Dim _pageSize As Integer = 25&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' *****************************************************************&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' ForumConfiguration&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;'&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Internal constructor for creating a new instance.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;' ******************************************************************/&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Public Sub New(ByVal parent As ForumConfiguration)&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Place holder for future work&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' *********************************************************************&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' LoadValuesFromConfigurationXml&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;'&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Loads the forums configuration values.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' ******************************************************************/&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Sub LoadValuesFromConfigurationXml(ByVal node As XmlNode)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Dim attributeCollection As XmlAttributeCollection = node.Attributes&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Get the attributes of the &amp;lt;forums&amp;gt; element&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;_pageSize =&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Int32.Parse(attributeCollection("defaultPageSize").Value)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Properties&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Public ReadOnly Property PageSize() As Integer&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Get&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Return _pageSize&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Get&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Property&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Class&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Namespace&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;This configuration section handler is compiled and then registered within an application.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;It can then be used within web.config:&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;configSections&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;sectionGroup name="system.web"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;section name="forums"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;type="AspNetForums.Configuration.ForumsConfigurationHandler, AspNetForums" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/sectionGroup&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/configSections&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;forums defaultPageSize = "25" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/system.web&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;This code example shows how you can create a custom configuration section. It's obviously&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;not a simple task. However, for controlling exactly how the configuration information&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;represents the data stored in the configuration file, it is the only option. If having a&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;custom configuration section seems to you like too much work just to store application&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;items, you're not alone.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6768644085119813044?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6768644085119813044/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6768644085119813044' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6768644085119813044'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6768644085119813044'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/storing-and-reading-custom-settings.html' title='Storing and Reading Custom Settings from the web.config File'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-7614826956377012602</id><published>2008-09-18T19:45:00.001+05:30</published><updated>2008-09-18T19:45:38.151+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mobile Controls - Customizing Output'/><title type='text'>Customizing Output for a Device</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The web.config file is as follows:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;deviceFilters&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;filter name="isHTML32" compare="PreferredRenderingType" argument="html32" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;filter name="isWML11" compare="PreferredRenderingType" argument="wml11" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;/deviceFilters&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The ASPX page is as follows:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;mobile:Form id="Form1" runat="server"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;DeviceSpecific&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;Choice Filter="isHTML32"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;HeaderTemplate&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Header visible only in HTML Browsers&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;BR&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;img Src="poweredbyaspnet.gif" border="0"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;HR&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/HeaderTemplate&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;FooterTemplate&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;HR&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Footer visible only in HTML Browsers&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/FooterTemplate&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/Choice&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;Choice&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Label id="Lable1" runat="server" &amp;gt;Powered by&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ASP.NET Visible on non-HTML browsers&amp;lt;/mobile:Label&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/Choice&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/DeviceSpecific&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Label id="Label1" runat="server"&amp;gt;Content of Mobile&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Form visible in all devices&amp;lt;/mobile:Label&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;It want is possible to provide a richer user experience by optimizing the output of a specific&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;device.You can do this by configuring device filters in your application's web.config&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;file. Using the results of that filter test, you can enable content to be rendered on a&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;device-specific basis. As shown in the previous web.config file, the first device filter provides&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;HTML 3.2 support and the second provides WML 1.1 support.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;All mobile controls support the capability to use a DeviceSpecific/Choice filter to&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;customize the output.The&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;mobile:Form&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;control (which is a&lt;/span&gt; &lt;em&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo-Italic"&gt;templated&lt;/span&gt;&lt;/em&gt; &lt;font face="Bembo" size="2"&gt;control) supports&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;header and footer templates as well. Combining these two features in the previous example&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;allows you to include a header and footer on browsers that support HTML.The&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;device that passes the &lt;font face="Courier" size="1"&gt;isHTML32&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;test will be sent HTML content, and all other devices&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;are sent the content in the default &lt;font face="Courier" size="1"&gt;&amp;lt;Choice&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;filter.&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7614826956377012602?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7614826956377012602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7614826956377012602' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7614826956377012602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7614826956377012602'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/customizing-output-for-device.html' title='Customizing Output for a Device'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-4602960518527427812</id><published>2008-09-18T19:44:00.001+05:30</published><updated>2008-09-18T19:44:23.548+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mobile Controls - Displaying ObjectList'/><title type='text'>Displaying ObjectList Information in a Table</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The ASPX page is as follows:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;mobile:Form id="Form1" runat="server"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:ObjectList id="ObjectList1" runat="server"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;LabelStyle-StyleReference="title"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;CommandStyle-StyleReference="subcommand" &amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/mobile:ObjectList&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Code here to retrieve Book Listing&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Fields returned are&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' - BookName&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' - BookCategory&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' - BookISBN&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ObjectList1.DataSource = myBookList&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ObjectList1.LabelField = "BookName"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ObjectList1.TableFields= "BookName;BookCategory;BookISBN"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ObjectList1.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;The ObjectList control is the mobile control equivalent to the ASP.NET DataGrid.The&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;default display of the ObjectList in all devices is a single column listing of links.You designate&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the field to be displayed as the link using the &lt;font face="Courier" size="1"&gt;LabelField&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;property. Clicking on&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the link takes you to another screen that displays all fields for that item.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;On mobile devices that have browsers that support HTML markup, it is possible to&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;display the initial listing in a tabular format by using the &lt;font face="Courier" size="1"&gt;TableFields&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;property. As&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;shown in this example, you need to separate each field that is to be displayed by a semicolon.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The first item in the TableField list is designated as the LabelField. Note that on&lt;/p&gt;&lt;br /&gt;&lt;p&gt;devices that do not support HTML markup, the ObjectList provides the default display.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4602960518527427812?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4602960518527427812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4602960518527427812' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4602960518527427812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4602960518527427812'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/displaying-objectlist-information-in.html' title='Displaying ObjectList Information in a Table'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-7753352863708979557</id><published>2008-09-18T19:42:00.001+05:30</published><updated>2008-09-18T19:42:58.815+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mobile Controls -  Automatic Paging'/><title type='text'>Configuring Automatic Paging of Content</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The ASPX page is as follows:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;mobile:Form id="Form1" Paginate="true" runat="server"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:List id="List1" runat="server"&amp;gt;&amp;lt;/mobile:List&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If Not IsPostBack&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim count AS Integer&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;For count = 1 To 100&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim listItem = New MobileListItem(count.ToString())&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;List1.Items.Add(listItem)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Next&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Because the screens of mobile devices are typically small and cannot display large&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;amounts of data,ASP.NET mobile controls provide the capability to automatically paginate&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;across large amounts of data by splitting them into multiple screens.The &lt;font face="Courier" size="1"&gt;form&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;control&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;is an example of a mobile control that contains this functionality.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;By setting the &lt;font face="Courier" size="1"&gt;Paginate&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;property of the form control, you enable this capability.The&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;control automatically inserts navigation constructs that are appropriate for the device in&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;question.This enables the users to page back and forth between multiple screens of data.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The TextView, List, and the ObjectList controls also support internal pagination.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7753352863708979557?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7753352863708979557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7753352863708979557' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7753352863708979557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7753352863708979557'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/configuring-automatic-paging-of-content.html' title='Configuring Automatic Paging of Content'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-973012195353274577</id><published>2008-09-18T19:41:00.001+05:30</published><updated>2008-09-18T19:41:24.577+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mobile Controls - Navigation'/><title type='text'>Navigation in a Mobile Web Form</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The ASPX page is as follows:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;mobile:Form id="Form1" runat="server"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:Label id="Label1" runat="server"&amp;gt;This is Form1&amp;lt;/mobile:Label&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:Link id="Link1" runat="server"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;NavigateUrl="#Form2"&amp;gt;Go To Form2&amp;lt;/mobile:Link&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:Link id="Link2" runat="server"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;NavigateUrl="#Form3"&amp;gt;Go To Form3&amp;lt;/mobile:Link&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:Form id="Form2" runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:Label id="Label2" runat="server"&amp;gt;This is Form2&amp;lt;/mobile:Label&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;mobile:Link id="Link3" runat="server"&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;NavigateUrl="#Form1"&amp;gt;Go To Form1&amp;lt;/mobile:Link&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;mobile:Link id="Link4" runat="server"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;NavigateUrl="#Form3"&amp;gt;Go To Form3&amp;lt;/mobile:Link&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Form id="Form3" runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Label id="Label3" runat="server"&amp;gt;This is Form3&amp;lt;/mobile:Label&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Command id="Command1" onclick="Command1_Click"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;runat="server"&amp;gt;Go To Form1&amp;lt;/mobile:Command&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Command id="Command2" onclick="Command2_Click"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;runat="server"&amp;gt;Go To Form2&amp;lt;/mobile:Command&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;In&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server" /&amp;gt;&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;block or codebehind:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;void Command1_Click(Object sender, EventArgs e) {&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ActiveForm = Form1;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;void Command2_Click(Object sender, EventArgs e) {&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ActiveForm = Form2;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Mobile ASP.NET Web Forms, unlike ASP.NET Web Forms, can have multiple form elements.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;By default, the first form on a mobile page becomes the active form.The&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;mobile:Link&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;&lt;font face="Times New Roman"&gt;control allows you to navigate from one form to another within a page.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The target of the link is set by the &lt;font face="Courier" size="1"&gt;NavigateUrl&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;property and takes the form of&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;#FormID&lt;/font&gt;&lt;font face="Times New Roman" size="2"&gt;, where&lt;/font&gt; &lt;font face="Courier" size="1"&gt;FormID&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;&lt;font face="Times New Roman"&gt;is the ID of the form that you want to navigate to.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;You can also programmatically make a form active by using the &lt;font face="Courier" size="1"&gt;ActiveForm&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;property&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;as shown in &lt;font face="Courier" size="1"&gt;Form3&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-973012195353274577?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/973012195353274577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=973012195353274577' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/973012195353274577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/973012195353274577'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/navigation-in-mobile-web-form.html' title='Navigation in a Mobile Web Form'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-2093544714712358467</id><published>2008-09-18T19:38:00.001+05:30</published><updated>2008-09-18T19:38:28.061+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mobile Controls - Web Form'/><title type='text'>Creating a Mobile Web Form</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;To declare an ASP.NET mobile page (a mobile Web Form), simply create a file with an&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;.ASPX extension and place it in a Web folder.The ASPX page must contain the following&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;directives and at least one&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;form&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;element:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" %&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Assembly="System.Web.Mobile" %&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Form id="Form1" runat="server"&amp;gt;Hello&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;mobile:Form id="Form2" runat="server"&amp;gt;World&amp;lt;/mobile:Form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;ASP.NET pages that use mobile controls must inherit from&lt;/font&gt; &lt;font face="Courier" size="1"&gt;System.Web.UI.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;MobileControls.MobilePage&lt;font face="Bembo" size="2"&gt;&lt;font face="Times New Roman"&gt;. Just like with a regular Web Form, you can also set&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;optional parameters such as &lt;font face="Courier" size="1"&gt;Language&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;in the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Page&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;directive.The second directive associates&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the &lt;font face="Courier" size="1"&gt;mobile&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;prefix with the mobile control namespace.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Note that HTML constructs such as &lt;font face="Courier" size="1"&gt;&amp;lt;HTML&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;and&lt;/font&gt; &lt;font face="Courier" size="1"&gt;&amp;lt;BODY&amp;gt;&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;are not present, as these tags&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;do not render properly in a mobile device that does not support HTML. One key difference&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;between a regular Web Form and a mobile Web Form is that you can have more&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;than one form control in a mobile Web Form.This allows a single Web Form to display&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;multiple screens in a mobile device using form elements.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Finally, note that mobile controls support are built into ASP.NET v1.1, which should&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;make the @ Register directive unnecessary.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2093544714712358467?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2093544714712358467/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2093544714712358467' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2093544714712358467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2093544714712358467'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-mobile-web-form.html' title='Creating a Mobile Web Form'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-4905098221262392697</id><published>2008-09-18T19:36:00.001+05:30</published><updated>2008-09-18T19:36:43.116+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='CallBack when a Cached'/><title type='text'>Implementing a CallBack when a Cached</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The capability to call a method whenever an item expires from the cache allows you to&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;build systems that can intelligently add data back into the cache.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;Script runat=server&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Shared reason As CacheItemRemovedReason&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Dim onRemove As CacheItemRemovedCallback&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Public Shared Sub ItemRemovedCallback(key As String,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;value As Object,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;removedReason As CacheItemRemovedReason)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Reason why the item was removed&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;reason = removedReason&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Reinsert the item into the Cache, but change the value&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Cache.Insert(key, "Item re-inserted")&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Public Sub Page_Load(sender As Object, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;onRemove = New CacheItemRemovedCallback(&lt;/p&gt;&lt;br /&gt;&lt;p&gt;AddressOf Me.ItemRemovedCallback)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;' Add an item to the Cache with the callback&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;If Is Nothing(Cache("Key1")) Then&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Cache.Insert("Key1", "In the Cache", Nothing,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;DateTime.Now.AddSeconds(10),&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;TimeSpan.Zero, CacheItemPriority.Low, onRemove)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Set the label value&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Label1.Text = Cache("Key1")&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/Script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Value of the Cache: &amp;lt;asp:label id="Label1" runat="server" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The capability of a function to be called when an item is removed from the cache is&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;very powerful. It allows you to reinsert the item or to report a reason as to why the item&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;was removed.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;The only caveat is that during the time between when the item is removed from the&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;cache, yet before the callback function is called, another request might ask for the item&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;from the cache and would not find it. Regardless, it's still a very powerful technique for&lt;/p&gt;&lt;br /&gt;&lt;p&gt;controlling how items are removed from the cache.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4905098221262392697?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4905098221262392697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4905098221262392697' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4905098221262392697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4905098221262392697'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/implementing-callback-when-cached.html' title='Implementing a CallBack when a Cached'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-5566667142956370238</id><published>2008-09-18T19:34:00.001+05:30</published><updated>2008-09-18T19:34:44.551+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Per-Request Caching'/><title type='text'>Using HttpContext for Per-Request Caching</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Storing data within&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;HttpContext.Current.Items&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;allows for data to exist for the duration&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;of the request and to be automatically discarded when the request is complete.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Public Function GetUserInfo(string username) As User&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Let's not go to the database each time we need the user's info&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' the userKey is a unique value that identifies the user, such as the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' username&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If (HttpContext.Current.Items(username) Is Nothing) Then&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;// Hang on to the data for this request only&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;HttpContext.Current.Items(username) = Provider.GetUserInfo(username);&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Return CType(HttpContext.Current.Items(username), User);&lt;/p&gt;&lt;br /&gt;&lt;p&gt;End Function&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;To see this code in action, see&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Users.cs&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;class in the ASP.NET forums source code.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In some specialized cases, you want to cache some data only for the duration of the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;request. A great example of this is in the ASP.NET forums (source code available at&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;www.asp.net&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;&lt;font face="Times New Roman"&gt;).&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The forums make use of personalization within each server control. A single page&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;may be composed of 10-12 server controls. Rather than each server control retrieving its&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;own set of data from the database, the code can reliably call the &lt;font face="Courier" size="1"&gt;GetUserInfo()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;function&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;repeatedly. If the item is not found in the &lt;font face="Courier" size="1"&gt;HttpContext.Items&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;collection-a special dictionary&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that exists for the duration of the request-it is created from the database and&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;added to &lt;font face="Courier" size="1"&gt;HttpContext.Items&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This technique is very powerful because it allows your code to remain modular and&lt;/p&gt;&lt;br /&gt;&lt;p&gt;to take advantage of a caching technique to improve performance.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5566667142956370238?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5566667142956370238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5566667142956370238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5566667142956370238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5566667142956370238'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/using-httpcontext-for-per-request.html' title='Using HttpContext for Per-Request Caching'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-7164097867141105308</id><published>2008-09-18T19:33:00.001+05:30</published><updated>2008-09-18T19:33:54.063+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Output Caching by HTTP Headers'/><title type='text'>Varying Output Caching by HTTP Headers</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;As demonstrated in Sections 4.6 and 4.7, it is possible to be very explicit about how&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;pages can be output cached.The last technique for controlling how pages can be cached&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;involves varying by HTTP headers presented by the client browser:&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;%@OutputCache Duration="60" VaryByParam="none"&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;VaryByHeader="Accept-Language" %&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;em&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier-Oblique"&gt;[content]&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;or&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;' Note, this only works for pages and not user controls&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Sub Page_Load(object As Sender, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetExpires(DateTime.Now.AddSeconds(100))&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetCacheability(HttpCacheability.Public)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetValidUntilExpires(true)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.VaryByHeaders("Accept-Language") = true;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;em&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier-Oblique"&gt;[content]&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;All browsers send over headers that provide information about the browser, or other relevant&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;information pertinent to the request. As discussed in Section 4.7, browsers provide&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;a user/agent header that allows ASP.NET to generate different content based on the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;browser type. In addition to the user/agent header, several other headers are sent over&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that you can vary by.The most common is the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Accept-Language&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;header.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The &lt;font face="Courier" size="1"&gt;Accept-Language&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;header provides information about the language the client&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;prefers. For example, for United States English, the value is &lt;font face="Courier" size="1"&gt;EN-US&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, whereas a request&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;from the United Kingdom might be &lt;font face="Courier" size="1"&gt;EN-EN&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, France is&lt;/font&gt; &lt;font face="Courier" size="1"&gt;FR-FR&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, and Japan is&lt;/font&gt; &lt;font face="Courier" size="1"&gt;JP-JP&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;When the output cache is varied by the &lt;font face="Courier" size="1"&gt;Accept-Language&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;header, different localized&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;versions of the page can be stored and served from the cache-assuming you've written&lt;/p&gt;&lt;br /&gt;&lt;p&gt;the code to do so.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7164097867141105308?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7164097867141105308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7164097867141105308' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7164097867141105308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7164097867141105308'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/varying-output-caching-by-http-headers.html' title='Varying Output Caching by HTTP Headers'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-7455602963347334345</id><published>2008-09-18T19:32:00.001+05:30</published><updated>2008-09-18T19:32:56.164+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Output Caching by Browser'/><title type='text'>Varying Output Caching by Browser</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;You can vary by browser the output cache for pages using two techniques; only the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;@OutputCache&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;directive is supported for User Control caching:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@OutputCache Duration="60" VaryByParam="none"&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;VaryByCustom="browser" %&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;em&gt;&lt;font face="Courier-Oblique" size="1"&gt;[content]&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;or&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Note, this only works for pages and not user controls&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Sub Page_Load(object As Sender, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Response.Cache.SetExpires(DateTime.Now.AddSeconds(100))&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetCacheability(HttpCacheability.Public)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetValidUntilExpires(true)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetVaryByCustom("browser")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;em&gt;&lt;font face="Courier-Oblique" size="1"&gt;[content]&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;ASP.NET server controls can render different content depending upon the user/agent&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;presented to the server during the request. All browsers present a user/agent that allows&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the server addressing the request to know the capabilities of the browser.This is regardless&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;of whether the browsers are desktop browsers such as IE, Netscape, or Opera, or&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;mobile/device browsers, such as the browser found in a RIM device, cellular phone, or&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;handhelds.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Many ASP.NET server controls can render different content that is better suited to&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the browser type making the request. A great example of this capability is existence of IE&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Web Controls and ASP.NET Mobile controls (both available at &lt;font face="Courier" size="1"&gt;www.asp.net&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;).These&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;controls intelligently detect the browser type.When desktop browsers are used, HTML is&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;rendered.When mobile browsers are used,WML is rendered.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Varying the cache by browser allows for the ASP.NET cache to store different versions&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;of the requested page in the cache based on the type of browser making the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;request.The only caveat is that only the browser type and major version number-IE&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;6.0, for example-are tracked. For example, versions 4.0, 4.1, and 4.5, of Netscape&lt;/p&gt;&lt;br /&gt;&lt;p&gt;browsers would all resolve to one entry within the cache.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7455602963347334345?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7455602963347334345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7455602963347334345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7455602963347334345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7455602963347334345'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/varying-output-caching-by-browser.html' title='Varying Output Caching by Browser'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-4486979688322762126</id><published>2008-09-18T19:30:00.000+05:30</published><updated>2008-09-18T19:31:00.778+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Output Caching'/><title type='text'>Varying Output Caching by Parameter(s)</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;There are two techniques for varying by parameters in pages; partial page caching only&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;supports the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;@OutputCache&lt;/span&gt; &lt;font face="Bembo" size="2"&gt;directive.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@OutputCache Duration="60" VaryByParam="productId" %&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;em&gt;&lt;font face="Courier-Oblique" size="1"&gt;[content specific to the product id value]&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;or&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Note, this only works for pages and not user controls&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Sub Page_Load(object As Sender, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Response.Cache.SetExpires(DateTime.Now.AddSeconds(100))&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetCacheability(HttpCacheability.Public)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetValidUntilExpires(true)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.VaryByParams("productId") = True&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;em&gt;&lt;font face="Courier-Oblique" size="1"&gt;[content specific to the product id value]&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Dynamic pages usually accept parameters and potentially display different output determined&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;by these parameters. A common example is a page used to display product information,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;such as &lt;font face="Courier" size="1"&gt;products.aspx?productId=10&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The page is passed a single parameter, the product ID, and the content is retrieved for&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that particular product. Output caching allows you to cache the results of a dynamically&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;generated page so you don't need to execute the page on each request.Varying the output&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;cache by parameters allows you to cache multiple views of the page based on parameters&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that affect the output, such as a products.aspx page that accepts a &lt;font face="Courier" size="1"&gt;productId&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;parameter.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Multiple parameters can be specified using the &lt;font face="Courier" size="1"&gt;@OutputCache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;directive by using a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;semicolon to separate items. For example, if you were generating output based on the&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;productId&lt;/font&gt; &lt;font face="Times New Roman" size="2"&gt;and the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;salesId&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Times New Roman"&gt;, you could specify the following:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@OutputCache Duration="60" VaryByParam="productId;salesId" %&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Using the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;@OutputCache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;directive, it is also possible to vary all parameters.This isn't a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;recommended approach, but if you're not sure how many parameters you depend upon,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;using &lt;font face="Courier" size="1"&gt;VaryByParam = "*"&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;will vary by all parameters. Conversely, using&lt;/font&gt; &lt;font face="Courier" size="1"&gt;VaryByParam =&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;"none" &lt;font face="Bembo" size="2"&gt;&lt;font face="Times New Roman"&gt;will vary by no parameters.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4486979688322762126?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4486979688322762126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4486979688322762126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4486979688322762126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4486979688322762126'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/varying-output-caching-by-parameters.html' title='Varying Output Caching by Parameter(s)'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-6883182877748630542</id><published>2008-09-18T19:29:00.001+05:30</published><updated>2008-09-18T19:29:53.486+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cache Dependency'/><title type='text'>Creating a Cache Dependency</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;As discussed in Section 4.3, the cache allows for items to be inserted or added to the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Cache along with several other parameters, such as time-based constraints or an instance&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;of&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;CacheDependency&lt;/span&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Sub Page_Load(object As Sender, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim stringArray As string {"Rob", "Steve", "Mike", "Anne"}&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Time based dependency for 60 minutes&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Cache.Insert("myArray-Time", stringArray, Nothing,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;DateTime.Now.AddMinutes(60), TimeSpan.Zero)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' File based dependency&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim fileDep = New CacheDependency(Server.MapPath("Products.xml"))&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Cache.Insert("myArray-File", stringArray, fileDep)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Key based dependency&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Cache.Insert("myKey", "key for dependencies")&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Dim keyDep = New CacheDependency(Nothing, "myKey")&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Cache.Insert("myArray-Key", stringArray, fileDep)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;In the previous examples, three types of dependencies are created:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Time-Time-based dependencies specify that an item is to remain in the cache&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;for the specified duration of time.This is the same functionality found when using&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the &lt;font face="Courier" size="1"&gt;@OutputCache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;directive and setting the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Duration&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;File-File-based dependencies specify that an item is to remain in the cache until&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the named file changes.Any output cached page is automatically made dependent&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;upon itself. However, it's possible-as demonstrated in this example-to use this&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;same functionality for entries within the Cache API.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="SeanSymbols" size="1"&gt;n&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;Key-Key-based dependencies specify that an item is to remain in the cache until&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;a related cache key changes.This is very powerful because any running ASP.NET&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;code can affect the cache key to enforce this relationship. For example, cascading&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;relationships can be established whereby one cache entry is changed or removed&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;and multiple other cache entries are affected.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dependencies provide a simple but powerful programming model for controlling&lt;/p&gt;&lt;br /&gt;&lt;p&gt;removal of resources from the cache when other resources change.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6883182877748630542?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6883182877748630542/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6883182877748630542' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6883182877748630542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6883182877748630542'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-cache-dependency.html' title='Creating a Cache Dependency'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-6956804275322368019</id><published>2008-09-18T19:26:00.001+05:30</published><updated>2008-09-18T19:26:39.305+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Caching - Retrieving Data'/><title type='text'>Retrieving Data from the Cache</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Retrieving objects stored within the cache is simple; there are two options for doing so:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Dictionary style-Using patterns similar to that of Session and Application.&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Cache.Get()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;API-The&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Get()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method accepts a single parameter that fetches the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;value of the named key.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Given the example used in Section 4.3 that added a dataset into the cache using the key&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;MyProducts&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, you could retrieve this value from the Cache:&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;' Get a value from the cache&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Sub Page_Load(object As Sender, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Dim ds As DataSet&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;If (Cache("MyProducts") Is Not Nothing) Then ' Uses Dictionary style API&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;ds = CType(Cache.Get("MyProducts"), DataSet) ' Uses Get() method&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;Getting items stored within the cache is very simple. Although both techniques-dictionary&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;style and &lt;font face="Courier" size="1"&gt;Get()&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;-are used in this example, the dictionary style access is the one&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;most frequently used.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-6956804275322368019?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/6956804275322368019/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=6956804275322368019' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6956804275322368019'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/6956804275322368019'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/retrieving-data-from-cache.html' title='Retrieving Data from the Cache'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-7440166681736371690</id><published>2008-09-18T19:24:00.001+05:30</published><updated>2008-09-18T19:24:55.898+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='cache - inserting data'/><title type='text'>Inserting Data into the Cache</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;There are several ways to add items into the Cache API:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Dictionary style-Similar to the way the Session or Application API is used.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Insert method-Inserts the named item into the cache and allows for additional&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;parameters that specify other cache behavior, such as when the item should be&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;removed from the cache.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Add method-Same as insert, but adds the item only if it did not already exist.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;In the following examples, &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;products&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;is assumed to be a dataset. However, it could be&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;any .NET class.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;' Add an item using the dictionary style API&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Cache("MyProducts") = products&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Insert an item using the overloaded Insert method&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Cache.Insert("MyProducts", products)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Insert an item and specify a cache dependency&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Cache.Insert("MyProducts", products, cacheDependency)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Insert an item and specify that the item exists for only 60 minutes&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Cache.Insert("MyProducts", products, Nothing,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;DateTime.Now.AddMinutes(60), TimeSpan.Zero)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Insert an item and specify that the item exists for only 60 minutes, has a&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' high priority and specify a callback function called when the item is&lt;/p&gt;&lt;br /&gt;&lt;p&gt;' removed from the cache&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Cache.Insert("MyProducts", products, Nothing, DateTime.Now.AddMinutes(60),&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;TimeSpan.Zero, CacheItemPriority.High, cacheCallBack)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Add an item using the Add method&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Cache.Add("MyProducts", products, cacheDependency,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;DateTime.Now.AddMinutes(60), TimeSpan.Zero,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;CacheItemPriority.High, cacheCallBack)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The Cache API, accessible simply as the Cache property within an ASP.NET page, is the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;underlying data store used by page output caching, partial page caching, and Web service&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;caching.There are many cases when caching the output of the page is not desirable, but&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;data can still be reused. One example is a listing of products or reports.The data is stored&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;in memory, but options within the page determine how the data is displayed.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Something to keep in mind when using the cache is that it is &lt;em&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo-Italic"&gt;scavenging&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;.As memory is&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;needed, items are removed from the cache using an LRU (least recently used) algorithm.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Therefore, before using an item from the cache it is always wise to verify that the item&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;exists and is not Nothing:&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;If (Cache("MyProducts") Is Not Nothing)&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;… Insert into the cache&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End If&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The various parameters accepted by&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Insert()&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;and&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Add()&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;provide control over how the&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;cache stores data.You can provide a &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;CacheDependency&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;, which then enforces a relationship&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;between the item stored within the cache and either a file or cache key.When the&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;file or cache key changes, the related entry within the cache is removed. It is also possible&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;to specify time-based constraints using a fixed point in time or a sliding window of&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;time. It's possible to control the priority of items stored within the cache using the&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;CacheItemPriority&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;&lt;span style="FONT-FAMILY: Times New Roman"&gt;enumeration-this affects how the scavenging algorithm removes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;items. Finally, you can specify a callback function that the cache will call when an item is&lt;/p&gt;&lt;br /&gt;&lt;p&gt;removed.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7440166681736371690?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7440166681736371690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7440166681736371690' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7440166681736371690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7440166681736371690'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/inserting-data-into-cache.html' title='Inserting Data into the Cache'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-9078184074963649721</id><published>2008-09-18T19:20:00.000+05:30</published><updated>2008-09-18T19:22:14.337+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Caching -  VaryByControl'/><title type='text'>Partial Page Output Caching Using VaryByControl</title><content type='html'>&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;VaryByControl&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;directive provides a helpful shortcut to vary the User Controls output&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;by a contained control.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;&amp;lt;%@ Imports Namespace="System.Data.SqlClient" %&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;%@ OutputCache Duration="60" VaryByControl="SortBy" %&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Sub Page_Load (sender As object, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Dim connection As New SqlConnection([your connection string])&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Dim command As New SqlCommand("BookSelection", connection)&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Mark as a stored procedure&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;command.CommandType = CommandType.StoredProcedure&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Set up a SQL parameter for the book type selected&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;command.Parameters.Add("@BookType",&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: ZapfDingbats"&gt;➥&lt;/span&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;SqlDbType.NVarChar, 25).Value =&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: ZapfDingbats"&gt;➥&lt;/span&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;SortBy.SelectedItem.Value&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;' Execute&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;connection.Open()&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;BookListing.DataSource = command.ExecuteReader()&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;BookListing.DataBind()&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;connection.Close()&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;form runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;Please select the types of books you are interested in:&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;asp:DropDownList AutoPostBack="true" id="SortBy" runat="server" &amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;asp:listitem &amp;gt;Technology&amp;lt;/asp:listitem&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;asp:listitem &amp;gt;Fiction&amp;lt;/asp:listitem&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;asp:listitem &amp;gt;Non-Fiction&amp;lt;/asp:listitem&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;br&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;asp:DataGrid runat="server" id="BookListing" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;strong&gt;&lt;span style="FONT-FAMILY: Bembo-Bold"&gt;Comments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Consider a User Control that displays a list of the top 10 books with a&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;SortBy&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;DropDownList containing Technology, Fiction, and Non-Fiction.Whenever a user&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;changes a value in the DropDownList the server returns data filtered by the value of&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;SortBy.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;The content generated by the User Control can be varied just as you can vary page&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;output cached responses. However, within a User Control, the name of the control,&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;SortBy&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;, is namespaced to the name of the containing control-&lt;/span&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;UserControl1:SortyBy&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;This allows multiple Top10 User Controls to be hosted in the same page without experiencing&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;naming collisions.&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;For example, if you had two of these User Controls on your page, they might have&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;the IDs &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Top10Books1&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;and&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Top10Books2&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;.&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Top10Books1:SortBy&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;and&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;Top10Books2:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;SortBy &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;are treated as separate drop-down controls.The&lt;/span&gt; &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;VaryByControl&lt;/span&gt; &lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;option simply&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="TEXT-ALIGN: left"&gt;allows you to avoid typing &lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;VaryByParam="Top10Books2:SortBy"&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;-instead simply type&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="FONT-SIZE: 0.6em; FONT-FAMILY: Courier"&gt;VaryByControl="SortBy"&lt;/span&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&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/7926983505765515035-9078184074963649721?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/9078184074963649721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=9078184074963649721' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/9078184074963649721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/9078184074963649721'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/partial-page-output-caching-using.html' title='Partial Page Output Caching Using VaryByControl'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-4560885184033286563</id><published>2008-09-18T19:17:00.001+05:30</published><updated>2008-09-18T19:17:19.293+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Caching'/><title type='text'>Page Output Caching</title><content type='html'>&lt;p align="left"&gt;&lt;span style="FONT-SIZE: 0.75em; FONT-FAMILY: Bembo"&gt;Page output caching can be accomplished declaratively using a page @&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;OutputCache&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;directive or programmatically using the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Response.Cache API&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.The following code samples&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;are equivalent:&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Sub Page_Load (sender As object, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetExpires(DateTime.Now.AddSeconds(100))&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetCacheability(HttpCacheability.Public)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Response.Cache.SetValidUntilExpires(true)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;' Set the timestamp&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;timestamp.Text = DateTime.Now.ToString()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;asp:Label id="timestamp" runat="server" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Bembo" size="2"&gt;Or&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;&amp;lt;%@ OutputCache Duration="100" VaryByParam="none" %&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;script runat="server"&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;timestamp.Text = DateTime.Now.ToString()&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;End Sub&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&amp;lt;asp:Label id="timestamp" runat="server" /&amp;gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;&lt;font face="Bembo-Bold"&gt;Comments&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Bembo" size="2"&gt;As you can clearly see in the code sample, the page&lt;/font&gt; &lt;font face="Courier" size="1"&gt;@OutputCache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;directive is much easier&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;to implement. However, the lower-level &lt;font face="Courier" size="1"&gt;Response.Cache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;API provides more flexibility&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;when necessary. In either case, the content for the response is generated once and&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;stored in memory before being sent back to the client.The contents are never written to&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;disk, but instead are kept in memory within the application using the Cache API.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;In the &lt;font face="Courier" size="1"&gt;@OutputCache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;directive example, the&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Duration&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;and&lt;/font&gt; &lt;font face="Courier" size="1"&gt;VaryByParam&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attributes are&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;required (if they are not specified, an exception is thrown detailing the requirements of&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;these attributes).The &lt;font face="Courier" size="1"&gt;Duration&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute is a time dependency, in seconds, used to control&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the lifetime of the cached response in memory.The &lt;font face="Courier" size="1"&gt;VaryByParam&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;attribute specifies&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;which parameters (in the &lt;font face="Courier" size="1"&gt;Request.Params&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;collection) should cause separate versions of&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the page to be stored in the cache.&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;The &lt;font face="Courier" size="1"&gt;SetValidUntilExpires()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;method on&lt;/font&gt; &lt;font face="Courier" size="1"&gt;Response.Cache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;is used to control a&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;nuance of HTTP caching. By default, this method is set to &lt;font face="Courier" size="1"&gt;true&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;when using the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;@OutputCache&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;directive. Conversely, the default is&lt;/font&gt; &lt;font face="Courier" size="1"&gt;false&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;when using the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;font face="Courier" size="1"&gt;Response.Cache API&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;.&lt;/font&gt; &lt;font face="Courier" size="1"&gt;SetValidUntilExpires()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;controls how ASP.NET honors cache&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;invalidation headers sent by browsers.When users click the Refresh button in the browser,&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;the browser sends an HTTP header to the server specifying that the requested content&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;cannot come from a cache.When &lt;font face="Courier" size="1"&gt;SetValidUntilExpires()&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;is&lt;/font&gt; &lt;font face="Courier" size="1"&gt;true&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, the HTTP&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;cache invalidation request sent by the browser is ignored and the request can be served&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;from the cache; when &lt;font face="Courier" size="1"&gt;false&lt;/font&gt;&lt;font face="Bembo" size="2"&gt;, the HTTP cache invalidation request is honored and the&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;request is removed from the cache. It's recommended to always set this to &lt;font face="Courier" size="1"&gt;true&lt;/font&gt; &lt;font face="Bembo" size="2"&gt;to guarantee&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;that the server can respond from the cache, otherwise a simple refresh in the&lt;/p&gt;&lt;br /&gt;&lt;p&gt;browser can remove the item from the cache.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4560885184033286563?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4560885184033286563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4560885184033286563' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4560885184033286563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4560885184033286563'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/page-output-caching.html' title='Page Output Caching'/><author><name>hazivali</name><uri>http://www.blogger.com/profile/12166895375962456310</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-7926983505765515035.post-5372844915870607849</id><published>2008-09-16T23:50:00.000+05:30</published><updated>2008-09-16T23:52:27.684+05:30</updated><title type='text'>Installing a Component in the Global Assembly Cache (GAC)</title><content type='html'>The Global Assembly Cache in the .NET Framework provides a central place for registering&lt;br /&gt;assemblies. Registered assemblies are then available to all applications, including&lt;br /&gt;the development environments like Visual Studio.NET and Web Matrix.The process of&lt;br /&gt;adding an assembly to the Global Assembly Cache can be compared to the process of&lt;br /&gt;registering COM components in the server, as is done in the case of Windows DNA&lt;br /&gt;applications.The first step involved in adding an assembly is to strong-name the assembly. A strong&lt;br /&gt;name is basically assigned to an assembly or a component to distinguish it from other&lt;br /&gt;assemblies and components existing in the GAC. A strong name consists of an assembly&lt;br /&gt;identity (name, version, and so on), a public key, and a digital signature.Assigning a strong name to an assembly ensures that it is unique, has version protection,&lt;br /&gt;and has code integrity. Assigning a strong name to an assembly is not a difficult task.&lt;br /&gt;&lt;br /&gt;You can use the sn.exe utility to generate strong names, which are then added to the&lt;br /&gt;code of the assembly. For example, to create a strong name for an assembly named sample.&lt;br /&gt;dll, you would write the following in the command prompt:&lt;br /&gt;c:\MyAssembly&amp;gt;sn -k sample.snk&lt;br /&gt;&lt;br /&gt;This would generate a strong name keypair and store it in a file named sample.snk.The&lt;br /&gt;file extension can be anything, but.SNK is normally used as a convention.The -k option&lt;br /&gt;creates a strong name keypair.There are other options that you can search for in MSDN.&lt;br /&gt;The second step is to associate the generated strong name file with the assembly.Add&lt;br /&gt;the following code to your assembly to associate the strong name. By default,Visual&lt;br /&gt;Studio .NET projects include skeleton declarations of these attributes in the AssemblyInfo file.&lt;br /&gt;&lt;br /&gt;Imports System.Reflection&lt;br /&gt;&amp;lt;assembly: AssemblyKeyFile(“sample.snk”)&amp;gt;&lt;br /&gt;Note here that the information regarding the file containing the strong name keypair is&lt;br /&gt;placed in the code file before any namespace declaration. Also, you must import the&lt;br /&gt;System.Reflection namespace in order for the statement to work, otherwise the compiler&lt;br /&gt;will not recognize the &amp;lt;assembly: AssemblyKeyFile(“sample.snk”)&amp;gt; statement.&lt;br /&gt;After compiling the assembly with the statements containing the strong name information&lt;br /&gt;being added to it, you now have to place the assembly into the GAC.You can do&lt;br /&gt;this manually by simply copying and pasting the assembly into the GAC, which is located&lt;br /&gt;at C:\WINNT\ASSEMBLY\.&lt;br /&gt;&lt;br /&gt;You can also use the gacutil.exe utility, installed with the .NET Framework. In order&lt;br /&gt;to add an assembly, you write the following on the command prompt:&lt;br /&gt;gacutil /i sample.dll&lt;br /&gt;The /i option is for installation. In order to remove an assembly from the GAC, you can&lt;br /&gt;use the same utility, as follows:&lt;br /&gt;gacutil /u sample.dll&lt;br /&gt;The /u option is for uninstalling or removing an assembly from the cache.Typing&lt;br /&gt;gacutil /? lists all of its options.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5372844915870607849?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5372844915870607849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5372844915870607849' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5372844915870607849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5372844915870607849'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/installing-component-in-global-assembly.html' title='Installing a Component in the Global Assembly Cache (GAC)'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-7909017691229959526</id><published>2008-09-16T23:34:00.000+05:30</published><updated>2008-09-16T23:50:21.545+05:30</updated><title type='text'>Data-binding a TreeView Control</title><content type='html'>If you have not worked with the TreeView control before, refer to section 3.8 for basic&lt;br /&gt;TreeView information. First, you need to add the TreeView to your page and set the&lt;br /&gt;treenodesrc property to the XML file that you’ll be creating.&lt;br /&gt;&amp;lt;mytree:treeview runat=”server” id=”myTree” treenodesrc=”cars.XML”&amp;gt;&lt;br /&gt;&amp;lt;/mytree:treeview&amp;gt;&lt;br /&gt;&lt;br /&gt;The next thing you need to do is create your XML file that you will use to bind the&lt;br /&gt;TreeView to:&lt;br /&gt;&amp;lt;?xml version=”1.0” encoding=”utf-8” ?&amp;gt;&lt;br /&gt;&amp;lt;TREENODES&amp;gt;&lt;br /&gt;&amp;lt;treenode text=”Cars”&amp;gt;&lt;br /&gt;&amp;lt;treenode text=”Ford” /&amp;gt;&lt;br /&gt;&amp;lt;treenode text=”Toyota” /&amp;gt;&lt;br /&gt;&amp;lt;treenode text=”Infiniti” /&amp;gt;&lt;br /&gt;&amp;lt;/treenode&amp;gt;&lt;br /&gt;&amp;lt;/TREENODES&amp;gt;&lt;br /&gt;When the page loads, the TreeView will generate its nodes from the XML file.&lt;br /&gt;&lt;br /&gt;It is not possible to directly data-bind a dataset to the TreeView Web Control.The data&lt;br /&gt;must first be translated to XML.You can use response.write, which writes the XML,&lt;br /&gt;or use XSLT to transform the dataset into the correct XML.When using XSLT, you can&lt;br /&gt;specify the XSLT file using the TreeNodeXsltSrc property of the TreeView. In addition&lt;br /&gt;to using XML to define the actual nodes of the TreeView, you can also use XML to&lt;br /&gt;define the style types by using the TreeNodeTypeSrc property of the TreeView control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7909017691229959526?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7909017691229959526/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7909017691229959526' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7909017691229959526'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7909017691229959526'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/data-binding-treeview-control.html' title='Data-binding a TreeView Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-8365877095473036085</id><published>2008-09-16T23:33:00.000+05:30</published><updated>2008-09-16T23:34:03.843+05:30</updated><title type='text'>Using the ToolBar IE Web Control</title><content type='html'>The first step is to install the IE Web Controls from Microsoft.The link to download and&lt;br /&gt;install these controls is as follows: &lt;a href="http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/asp_dot_net_servercontrols/webcontrols/default.asp"&gt;http://msdn.microsoft.com/downloads/samples/&lt;br /&gt;internet/default.asp?url=/downloads/samples/internet/asp_dot_net_&lt;br /&gt;servercontrols/webcontrols/default.asp&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next, you need to add a reference to the Web Controls on your page:&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”ieControls”&lt;br /&gt;Namespace=”Microsoft.Web.UI.WebControls”&lt;br /&gt;Assembly=”Microsoft.Web.UI.WebControls” %&amp;gt;&lt;br /&gt;&amp;lt;%@ import namespace=”Microsoft.Web.UI.WebControls” %&amp;gt;&lt;br /&gt;Then, you add the toolbar to your page:&lt;br /&gt;&amp;lt;iecontrols:Toolbar id=”myToolbar” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;/ie:Toolbar&amp;gt;&lt;br /&gt;&lt;br /&gt;Lastly, you add the buttons that you want to appear on your toolbar:&lt;br /&gt;&amp;lt;iecontrols:Toolbar id=”myToolbar” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;iecontrols:ToolbarButton Text=”First Button” /&amp;gt;&lt;br /&gt;&amp;lt;iecontrols:ToolbarSeparator /&amp;gt;&lt;br /&gt;&amp;lt;iecontrols:ToolbarButton Text=”&amp;lt;b&amp;gt;Second Button&amp;lt;/b&amp;gt;” /&amp;gt;&lt;br /&gt;&amp;lt;/iecontrols:Toolbar&amp;gt;&lt;br /&gt;&lt;br /&gt;The toolbar control is a quick way to get a nice-looking toolbar working on your site.&lt;br /&gt;Notice in this example that you can even add rich content to the button text.This&lt;br /&gt;enables you to use HTML on your buttons.You can also set the ImageUrl property of&lt;br /&gt;the button tag to use an image as your button.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-8365877095473036085?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/8365877095473036085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=8365877095473036085' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8365877095473036085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8365877095473036085'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/using-toolbar-ie-web-control.html' title='Using the ToolBar IE Web Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-5630434148019461636</id><published>2008-09-16T23:32:00.000+05:30</published><updated>2008-09-16T23:33:15.499+05:30</updated><title type='text'>Using the TabControl and PageView IE Web Controls</title><content type='html'>The first step is to install the IE Web Controls from Microsoft.The link to download and&lt;br /&gt;install these controls is as follows: &lt;a href="http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/asp_dot_net_servercontrols/webcontrols/default.asp"&gt;http://msdn.microsoft.com/downloads/samples/&lt;br /&gt;internet/default.asp?url=/downloads/samples/internet/asp_dot_net_&lt;br /&gt;servercontrols/webcontrols/default.asp&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next, you need to add a reference to the Web Controls on your page:&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”ieControls”&lt;br /&gt;Namespace=”Microsoft.Web.UI.WebControls”&lt;br /&gt;Assembly=”Microsoft.Web.UI.WebControls” %&amp;gt;&lt;br /&gt;&amp;lt;%@ import namespace=”Microsoft.Web.UI.WebControls” %&amp;gt;&lt;br /&gt;Then you add your tabstrip.This is the control that generates the tabs that users click to&lt;br /&gt;change pages:&lt;br /&gt;&amp;lt;IECONTROLS:TABSTRIP id=”myTabStrip” runat=”server” TargetID=”myMultiPage”&lt;br /&gt;Orientation=”Vertical”&amp;gt;&lt;br /&gt;&amp;lt;IECONTROLS:Tab Text=”Tab 1”&amp;gt;&amp;lt;/IECONTROLS:Tab&amp;gt;&lt;br /&gt;&amp;lt;IECONTROLS:TabSeparator&amp;gt;&amp;lt;/IECONTROLS:TabSeparator&amp;gt;&lt;br /&gt;&amp;lt;IECONTROLS:Tab Text=”Tab 2”&amp;gt;&amp;lt;/IECONTROLS:Tab&amp;gt;&lt;br /&gt;&amp;lt;IECONTROLS:TabSeparator DefaultStyle=”height:100%;”&amp;gt;&lt;br /&gt;&amp;lt;/IECONTROLS:TabSeparator&amp;gt;&lt;br /&gt;&amp;lt;/IECONTROLS:TABSTRIP&amp;gt;&lt;br /&gt;Lastly, you need to add your multipage control that contains the different pages that will&lt;br /&gt;be viewed when users select each tab:&lt;br /&gt;&amp;lt;IECONTROLS:MULTIPAGE id=”myMultiPage” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;IECONTROLS:PAGEVIEW&amp;gt;&lt;br /&gt;Page 1&lt;br /&gt;&amp;lt;/IECONTROLS:PAGEVIEW&amp;gt;&lt;br /&gt;&amp;lt;IECONTROLS:PAGEVIEW&amp;gt;&lt;br /&gt;Page 2&lt;br /&gt;&amp;lt;/IECONTROLS:PAGEVIEW&amp;gt;&lt;br /&gt;&amp;lt;/IECONTROLS:MULTIPAGE&amp;gt;&lt;br /&gt;&lt;br /&gt;Notice that there is a property on the tabstrip control called TargetID.This must be set&lt;br /&gt;to the ID of the multipage control that will be working with the tabstrip.When the&lt;br /&gt;users click on the tab, the tabstrip will then tell the PageView to show the corresponding&lt;br /&gt;page.When working with the multipage control, you can add any type of ASP.NET&lt;br /&gt;or HTML between the opening and closing PageView tags. In this example, the tabstrip&lt;br /&gt;is running vertically, but you can also set this value to horizontal.To do so, you simply&lt;br /&gt;need to set the Orientation property to horizontal.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5630434148019461636?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5630434148019461636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5630434148019461636' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5630434148019461636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5630434148019461636'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/using-tabcontrol-and-pageview-ie-web.html' title='Using the TabControl and PageView IE Web Controls'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-1542738940637716005</id><published>2008-09-16T19:10:00.000+05:30</published><updated>2008-09-16T19:59:45.977+05:30</updated><title type='text'>Dynamically Adding Controls to a Web Form</title><content type='html'>You can add controls to any class that exposes a Controls() collection property by&lt;br /&gt;using the Class.Controls.Add() method. In this example, the user chooses which control&lt;br /&gt;should be added to the page. The PlaceHolder control can be used to specify&lt;br /&gt;exactly where on a Web Form you want your new control to appear, but otherwise is&lt;br /&gt;not necessary for this technique to work.&lt;br /&gt;&lt;br /&gt;The ASPX page is as follows:&lt;br /&gt;&amp;lt;form id=”code0307” method=”post” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;asp:DropDownList id=”DropDownList1” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;asp:ListItem Value=”Simple Text Control (code0301)”&amp;gt;&lt;br /&gt;Simple Text Control (code0301)&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;&amp;lt;asp:ListItem Value=”RainbowLabel (code0302)”&amp;gt;RainbowLabel&lt;br /&gt;(code0302)&amp;lt;/asp:ListItem&amp;gt;&lt;br /&gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;br /&gt;&amp;lt;asp:Button id=”Button1” runat=”server” Text=”Select”&lt;br /&gt;onclick=”Button1_Click”&amp;gt;&amp;lt;/asp:Button&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;&amp;lt;asp:PlaceHolder id=”PlaceHolder1” runat=”server”&amp;gt;&amp;lt;/asp:PlaceHolder&amp;gt;&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;In &amp;lt;script runat=”server” /&amp;gt; block or codebehind:&lt;br /&gt;Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)&lt;br /&gt;‘ Initialize Placeholder&lt;br /&gt;PlaceHolder1.Controls.Clear()&lt;br /&gt;Select Case DropDownList1.SelectedIndex&lt;br /&gt;Case 0:&lt;br /&gt;Dim SimpleText As AspNetCookbook.code0301vb = _&lt;br /&gt;New AspNetCookbook.code0301vb()&lt;br /&gt;SimpleText.Text = “This is the simple text control from Code 3.01.”&lt;br /&gt;PlaceHolder1.Controls.Add(SimpleText)&lt;br /&gt;Exit Select&lt;br /&gt;Case 1:&lt;br /&gt;Dim RainbowText As AspNetCookbook.RainbowLabel = _&lt;br /&gt;New AspNetCookbook.RainbowLabel()&lt;br /&gt;RainbowText.Text = “This is the RainbowText control from code 3.02.”&lt;br /&gt;PlaceHolder1.Controls.Add(RainbowText)&lt;br /&gt;Exit Select&lt;br /&gt;End Select&lt;br /&gt;End Sub&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-1542738940637716005?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/1542738940637716005/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=1542738940637716005' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1542738940637716005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1542738940637716005'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/dynamically-adding-controls-to-web-form.html' title='Dynamically Adding Controls to a Web Form'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-9136252511621602741</id><published>2008-09-12T16:06:00.000+05:30</published><updated>2008-09-12T16:08:13.282+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Creating Templated Control'/><title type='text'>Creating a Templated Control</title><content type='html'>This example creates a simple templated control. It displays the current time on the server&lt;br /&gt;on which it runs and allows you to add dynamic text and so on.&lt;br /&gt;First, the main control class, DateTimeControl:&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Web.UI&lt;br /&gt;Imports System.Web.UI.WebControls&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;Namespace AspNet&lt;br /&gt;&amp;lt;ToolboxData(“&amp;lt;{0}:DateTimeControl runat=server&amp;gt;&amp;lt;/{0}:DateTimeControl&amp;gt;”), _&lt;br /&gt;ParseChildren(True)&amp;gt; _&lt;br /&gt;Public Class DateTimeControl&lt;br /&gt;Inherits Control&lt;br /&gt;Implements INamingContainer&lt;br /&gt;Private _template As ITemplate&lt;br /&gt;Private _container As DateTimeContainer&lt;br /&gt;Private _text As String&lt;br /&gt;&amp;lt;TemplateContainer(GetType(DateTimeContainer))&amp;gt; _&lt;br /&gt;Public Overridable Property Template() As ITemplate&lt;br /&gt;Get&lt;br /&gt;Return _template&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal Value As ITemplate)&lt;br /&gt;_template = Value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Public Overridable ReadOnly Property Container() As DateTimeContainer&lt;br /&gt;Get&lt;br /&gt;&lt;br /&gt;Return _container&lt;br /&gt;End Get&lt;br /&gt;End Property&lt;br /&gt;Public Overridable Property Text() As String&lt;br /&gt;Get&lt;br /&gt;Return _text&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal Value As String)&lt;br /&gt;_text = Value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Public Overridable ReadOnly Property DateTime() As String&lt;br /&gt;Get&lt;br /&gt;Return System.DateTime.Now.ToShortTimeString()&lt;br /&gt;End Get&lt;br /&gt;End Property&lt;br /&gt;Protected Overrides Sub OnDataBinding(ByVal e As EventArgs)&lt;br /&gt;EnsureChildControls()&lt;br /&gt;MyBase.OnDataBinding(e)&lt;br /&gt;End Sub ‘OnDataBinding&lt;br /&gt;Protected Overrides Sub CreateChildControls()&lt;br /&gt;If Not (Template Is Nothing) Then&lt;br /&gt;_container = New DateTimeContainer(Text, DateTime)&lt;br /&gt;Template.InstantiateIn(Container)&lt;br /&gt;Controls.Add(Container)&lt;br /&gt;Else&lt;br /&gt;Controls.Add(New LiteralControl(“” + [Text] + “ “ + DateTime))&lt;br /&gt;End If&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;Now let’s take a look at the container control DateTimeContainer. It enables you to use&lt;br /&gt;&amp;lt;%# Container.Text %&amp;gt; and so forth.&lt;br /&gt;Public Class DateTimeContainer&lt;br /&gt;Inherits Control&lt;br /&gt;Implements INamingContainer&lt;br /&gt;Private _text As String&lt;br /&gt;Private _dateTime As String&lt;br /&gt;Public Sub New(ByVal text As String, ByVal dateTime As String)&lt;br /&gt;&lt;br /&gt;Me._text = text&lt;br /&gt;Me._dateTime = dateTime&lt;br /&gt;End Sub ‘New&lt;br /&gt;Public ReadOnly Property Text() As String&lt;br /&gt;Get&lt;br /&gt;Return _text&lt;br /&gt;End Get&lt;br /&gt;End Property&lt;br /&gt;Public ReadOnly Property DateTime() As String&lt;br /&gt;Get&lt;br /&gt;Return _dateTime&lt;br /&gt;End Get&lt;br /&gt;End Property&lt;br /&gt;End Class&lt;br /&gt;End Namespace&lt;br /&gt;&lt;br /&gt;This control allows you to add a template and thus choose how you want the data to be&lt;br /&gt;presented.The control is built using two classes—DateTimeControl is the actual control&lt;br /&gt;you add to the page and DateTimeContainer is the container control that holds the&lt;br /&gt;actual template data. Use of a container class is, strictly speaking, not necessary if you&lt;br /&gt;don’t want to use custom properties. If you just want to display static content, you can&lt;br /&gt;instantiate the control in a Panel control or a similar control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-9136252511621602741?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/9136252511621602741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=9136252511621602741' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/9136252511621602741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/9136252511621602741'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-templated-control.html' title='Creating a Templated Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-9143664535616023485</id><published>2008-09-12T16:04:00.000+05:30</published><updated>2008-09-12T16:06:46.924+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Creting Data-bound Conrol'/><title type='text'>Creating a Data-bound Control</title><content type='html'>This example shows you how to create a simple and original data-bound custom server&lt;br /&gt;control—a data-bound bulleted list.The CustomBulletedList class is as follows:&lt;br /&gt;&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Web.UI&lt;br /&gt;Imports System.Web.UI.WebControls&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;Imports System.Collections&lt;br /&gt;Imports System.Text&lt;br /&gt;Public Class CustomBulletedList&lt;br /&gt;Inherits System.Web.UI.WebControls.WebControl&lt;br /&gt;Private _html As New StringBuilder()&lt;br /&gt;Private _dataSource As IEnumerable&lt;br /&gt;Public Property DataSource() As IEnumerable&lt;br /&gt;Get&lt;br /&gt;Return _dataSource&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal value As IEnumerable)&lt;br /&gt;_dataSource = value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Private Sub CreateBulletedList()&lt;br /&gt;Dim dataSource As IEnumerable = Nothing&lt;br /&gt;Try&lt;br /&gt;dataSource = Me._dataSource&lt;br /&gt;Catch&lt;br /&gt;End Try&lt;br /&gt;If Not (dataSource Is Nothing) Then&lt;br /&gt;_html.Append(“&amp;lt;ul&amp;gt;”)&lt;br /&gt;Dim dataObject As Object&lt;br /&gt;For Each dataObject In dataSource&lt;br /&gt;_html.Append(“&amp;lt;li&amp;gt;”)&lt;br /&gt;_html.Append(dataObject)&lt;br /&gt;_html.Append(“&amp;lt;/li&amp;gt;”)&lt;br /&gt;Next dataObject&lt;br /&gt;_html.Append(“&amp;lt;/ul&amp;gt;”)&lt;br /&gt;End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Public Overrides Sub DataBind()&lt;br /&gt;MyBase.OnDataBinding(EventArgs.Empty)&lt;br /&gt;CreateBulletedList()&lt;br /&gt;End Sub&lt;br /&gt;Protected Overrides Sub Render(ByVal output As HtmlTextWriter)&lt;br /&gt;output.Write(_html)&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;To use this control, you need to do the following:&lt;br /&gt;&amp;lt;%@ Page Language=”VB” %&amp;gt;&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”AspNet” Namespace=”AspNet”&lt;br /&gt;Assembly=”AspNet” %&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN” &amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Data Bound Controls&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;script language=”vb” runat=”server”&amp;gt;&lt;br /&gt;Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)&lt;br /&gt;listControl.DataSource = New String() {“Test 1”, “Test 2”, “Test 3”}&lt;br /&gt;listControl.DataBind()&lt;br /&gt;End Sub&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;AspNet:CustomBulletedList id=”listControl” runat=”server”/&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;This control allows you to data-bind any data source that is derived from IEnumerable&lt;br /&gt;to it—the content will be listed in bulleted format. Overriding the DataBind method is&lt;br /&gt;the critical point in this control.When this method is called, it is trying to bind to the&lt;br /&gt;data source and call the CreateBulletedList method.&lt;br /&gt;CreateBulletedList loops through all of the data objects in the data source and&lt;br /&gt;saves them to be outputted as bulleted lines.&lt;br /&gt;By overriding the Render method, you can control the rendering of the control, and&lt;br /&gt;render it exactly as you see fit.You should always opt for this approach when performance&lt;br /&gt;is an issue (and when isn’t it?), because it is much faster than overriding the&lt;br /&gt;CreateChildControls method.&lt;br /&gt;One last point you should take note of is that you should always use a StringBuilder&lt;br /&gt;instead of a regular string as the HTML output source. Using regular string objects will&lt;br /&gt;seriously degrade the performance of your custom control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-9143664535616023485?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/9143664535616023485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=9143664535616023485' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/9143664535616023485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/9143664535616023485'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-data-bound-control.html' title='Creating a Data-bound Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-888521699411430182</id><published>2008-09-12T16:02:00.000+05:30</published><updated>2008-09-12T16:04:53.007+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Composite Control'/><title type='text'>Creating a Composite Control</title><content type='html'>This example shows you how to create a very simple yet useful composite control.The&lt;br /&gt;control is a composition of a TextBox and a validator, and the control can be used to validate&lt;br /&gt;email addresses.The EmailTextBox class is as follows:&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Web.UI&lt;br /&gt;Imports System.Web.UI.WebControls&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;Imports System.ComponentModel.Design&lt;br /&gt;Namespace AspNetPublic Class EmailTextBox&lt;br /&gt;Inherits System.Web.UI.WebControls.WebControl&lt;br /&gt;Implements INamingContainer&lt;br /&gt;Private textBox As textBox&lt;br /&gt;Private validator As RegularExpressionValidator&lt;br /&gt;Public Property Text() As String&lt;br /&gt;Get&lt;br /&gt;EnsureChildControls()&lt;br /&gt;Return textBox.Text&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal Value As String)&lt;br /&gt;EnsureChildControls()&lt;br /&gt;textBox.Text = Value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Public Property ErrorMessage() As String&lt;br /&gt;Get&lt;br /&gt;EnsureChildControls()&lt;br /&gt;Return validator.ErrorMessage&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal Value As String)&lt;br /&gt;EnsureChildControls()&lt;br /&gt;validator.ErrorMessage = Value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Public Overrides ReadOnly Property Controls() As ControlCollection&lt;br /&gt;Get&lt;br /&gt;EnsureChildControls()&lt;br /&gt;Return MyBase.Controls&lt;br /&gt;End Get&lt;br /&gt;End Property&lt;br /&gt;Protected Overrides Sub CreateChildControls()&lt;br /&gt;Controls.Clear()&lt;br /&gt;textBox = New TextBox&lt;br /&gt;validator = New RegularExpressionValidator&lt;br /&gt;Controls.Add(textBox)&lt;br /&gt;Controls.Add(validator)&lt;br /&gt;textBox.ID = “Email1”&lt;br /&gt;validator.ControlToValidate = textBox.ID&lt;br /&gt;‘A typical email address regular expression&lt;br /&gt;validator.ValidationExpression = “^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}&lt;br /&gt;\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))&lt;br /&gt;([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$”&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;End Namespace&lt;br /&gt;To use this control, you need to do the following:&lt;br /&gt;&amp;lt;%@ Page language=”VB” %&amp;gt;&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”AspNet” Namespace=”AspNet”&lt;br /&gt;Assembly=”AspNet” %&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN” &amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;code0304&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form id=”Form1” method=”post” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;AspNet:EmailTextBox&lt;br /&gt;ID=”EmailTextBox1”&lt;br /&gt;ErrorMessage=”You must provide a valid email address!”&lt;br /&gt;runat=”server”&lt;br /&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;This control validates the input in the TextBox. If the input is not a valid email address&lt;br /&gt;an error message appears. Controls like this one are useful on pages that contain a lot of&lt;br /&gt;user input that needs to be validated.You can easily extend this control to use several&lt;br /&gt;validator types, allow the page developer to define his/her own validation expression,&lt;br /&gt;and so on.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-888521699411430182?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/888521699411430182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=888521699411430182' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/888521699411430182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/888521699411430182'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-composite-control.html' title='Creating a Composite Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-73323324250642042</id><published>2008-09-12T15:59:00.000+05:30</published><updated>2008-09-12T16:02:36.436+05:30</updated><title type='text'>Creating ViewState-Enabled Control Properties</title><content type='html'>This example shows you how to create properties for your controls that retain their state&lt;br /&gt;using ViewState.&lt;br /&gt;The ViewStateControl class:&lt;br /&gt;&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Web.UI&lt;br /&gt;Imports System.Web.UI.WebControls&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;Public Class ViewStateControl&lt;br /&gt;Inherits System.Web.UI.WebControls.WebControl&lt;br /&gt;Public Property [Text]() As String&lt;br /&gt;Get&lt;br /&gt;Dim _text As String = CStr(ViewState(“Text”))&lt;br /&gt;If _text Is Nothing Then&lt;br /&gt;Return String.Empty&lt;br /&gt;Else&lt;br /&gt;Return _text&lt;br /&gt;End If&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal Value As String)&lt;br /&gt;ViewState(“Text”) = Value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)&lt;br /&gt;writer.Write([Text])&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;To use this control, you need to do the following:&lt;br /&gt;&amp;lt;%@ Page language=”VB” %&amp;gt;&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”AspNet” Namespace=”AspNet”&lt;br /&gt;Assembly=”AspNet” %&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN” &amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;code0303&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;script language=”VB” runat=”server”&amp;gt;&lt;br /&gt;Sub Page_Load(Sender As Object, E As EventArgs)&lt;br /&gt;If Not IsPostBack Then&lt;br /&gt;Dim RandomGenerator As Random&lt;br /&gt;RandomGenerator = New Random(DateTime.Now.Millisecond)&lt;br /&gt;ViewStateControl1.Text = RandomGenerator.Next(1,100)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;form id=”Form1” method=”post” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;AspNet:ViewStateControl id=”ViewStateControl1” runat=”server”/&amp;gt;&lt;br /&gt;&amp;lt;asp:linkbutton text=”PostBack test” runat=”server”/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;This control property called Text will retain its state on postbacks—as you see, it is quite&lt;br /&gt;easy to get properties to retain their state by using the ViewState property, and this&lt;br /&gt;technique is recommended for most Web Control properties.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-73323324250642042?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/73323324250642042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=73323324250642042' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/73323324250642042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/73323324250642042'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/creating-viewstate-enabled-control.html' title='Creating ViewState-Enabled Control Properties'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-5358766932747665909</id><published>2008-09-11T17:18:00.000+05:30</published><updated>2008-09-11T17:21:00.601+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web Controls'/><title type='text'>Extending Existing Web Controls</title><content type='html'>This example shows how to extend the functionality of an existing control—the Label&lt;br /&gt;control—and turn it into a RainbowLabel.This is accomplished through the use of&lt;br /&gt;inheritance—RainbowLabel is a subclass of the System.Web.UI.WebControls.Label class.&lt;br /&gt;The RainbowLabel class is as follows:&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Web.UI&lt;br /&gt;Imports System.Web.UI.WebControls&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;Public Class RainbowLabel&lt;br /&gt;Inherits System.Web.UI.WebControls.Label&lt;br /&gt;Public Property EnableRainbowMode() As Boolean&lt;br /&gt;Get&lt;br /&gt;If ViewState(“EnableRainbowMode”) Is Nothing Then&lt;br /&gt;Return True&lt;br /&gt;Else&lt;br /&gt;Return Boolean.Parse(CStr(ViewState(“EnableRainbowMode”)))&lt;br /&gt;End If&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal Value As Boolean)&lt;br /&gt;ViewState(“EnableRainbowMode”) = Value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Protected Overrides Sub Render(ByVal output As HtmlTextWriter)&lt;br /&gt;If EnableRainbowMode Then&lt;br /&gt;output.Write(ColorizeString([Text]))&lt;br /&gt;Else&lt;br /&gt;output.Write([Text])&lt;br /&gt;End If&lt;br /&gt;End Sub ‘Render&lt;br /&gt;Private Function ColorizeString(ByVal input As String) As String&lt;br /&gt;Dim output As New System.Text.StringBuilder(input.Length)&lt;br /&gt;Dim rand As Random = New Random(DateTime.Now.Millisecond)&lt;br /&gt;Dim i As Integer&lt;br /&gt;For i = 0 To input.Length - 1&lt;br /&gt;Dim red As Integer = rand.Next(0, 255)&lt;br /&gt;Dim green As Integer = rand.Next(0, 255)&lt;br /&gt;Dim blue As Integer = rand.Next(0, 255)&lt;br /&gt;output.Append(“&amp;lt;font color=””#”)&lt;br /&gt;output.Append(Convert.ToString(red, 16))&lt;br /&gt;output.Append(Convert.ToString(green, 16))&lt;br /&gt;output.Append(Convert.ToString(blue, 16))&lt;br /&gt;output.Append(“””&amp;gt;”)&lt;br /&gt;output.Append(input.Substring(i, 1))&lt;br /&gt;output.Append(“&amp;lt;/font&amp;gt;”)&lt;br /&gt;Next i&lt;br /&gt;Return output.ToString()&lt;br /&gt;End Function&lt;br /&gt;End Class&lt;br /&gt;To use this control, you need to do the following:&lt;br /&gt;&amp;lt;%@ Page language=”VB” %&amp;gt;&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”AspNetCookbook” Namespace=”AspNetCookbook”&lt;br /&gt;Assembly=”AspNetCookbook” %&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN” &amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;03 Custom Controls - 02 Extending Existing Web Controls&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form id=”Form1” method=”post” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;AspNetCookbook:RainbowLabel text=”This is a rainbow colored test string”&lt;br /&gt;runat=”server”/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;AspNetCookbook:RainbowLabel EnableRainbowMode=”false”&lt;br /&gt;text=”This is a test string” runat=”server”/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;This control creates a rainbow-ish pattern in the text it displays.This is accomplished by&lt;br /&gt;encapsulating each character in &amp;lt;font&amp;gt; tags.The color on each character is randomized.&lt;br /&gt;Although perhaps not the most useful control, it does demonstrate how easy it is to&lt;br /&gt;extend the functionality of existing Web Controls. It is worth noting that the Label control&lt;br /&gt;should not be overlooked as a powerful control on which to build—the validation&lt;br /&gt;controls all inherit from the simple Label control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5358766932747665909?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5358766932747665909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5358766932747665909' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5358766932747665909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5358766932747665909'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/extending-existing-web-controls.html' title='Extending Existing Web Controls'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-8518868446219985346</id><published>2008-09-11T17:16:00.000+05:30</published><updated>2008-09-11T17:18:36.105+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Custom Conrols'/><title type='text'>Declaring a Simple Custom Control</title><content type='html'>This example demonstrates how easy it is to create custom controls in ASP.NET, especially&lt;br /&gt;when compared to COM components.You simply create a class that inherits from&lt;br /&gt;System.Web.UI.Control or System.Web.UI.WebControls.WebControl and give it&lt;br /&gt;whatever properties and methods you need. In Visual Studio .NET, you would normally&lt;br /&gt;do this by creating a new Web Control Library project.You override its Render()&lt;br /&gt;method to control its output, and you have a very simple yet powerful tool for encapsulating&lt;br /&gt;and reusing user interface logic.&lt;br /&gt;The code0301vb class is as follows:&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;Imports System.Web.UI&lt;br /&gt;Namespace AspNetCookbook&lt;br /&gt;&amp;lt;DefaultProperty(“Text”), ToolboxData(“&amp;lt;{0}:code0301vb&lt;br /&gt;runat=server&amp;gt;&amp;lt;/{0}:code0301vb&amp;gt;”)&amp;gt; Public Class code0301vb&lt;br /&gt;Inherits System.Web.UI.WebControls.WebControl&lt;br /&gt;Dim _text As String&lt;br /&gt;&amp;lt;Bindable(True), Category(“Appearance”),&lt;br /&gt;DefaultValue(“”)&amp;gt; Property [Text]() As String&lt;br /&gt;Get&lt;br /&gt;Return _text&lt;br /&gt;End Get&lt;br /&gt;Set(ByVal Value As String)&lt;br /&gt;_text = Value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Protected Overrides Sub Render(&lt;br /&gt;ByVal output As System.Web.UI.HtmlTextWriter)&lt;br /&gt;output.Write([Text])&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;End Namespace&lt;br /&gt;To reference a custom control on a Web Form, you need to add a Register directive to&lt;br /&gt;the page, and specify three parameters.The TagPrefix is used for all controls from this&lt;br /&gt;namespace and assembly when they are declared on the page, and can be anything but&lt;br /&gt;asp, which is reserved for the built-in Web Controls that ASP.NET provides. Next, the&lt;br /&gt;namespace in which the controls reside must be specified. Finally, the name of the&lt;br /&gt;assembly, without any path information or the .DLL extension, is specified for the&lt;br /&gt;Assembly parameter. An example of this follows:&lt;br /&gt;&amp;lt;%@ Page language=”VB” %&amp;gt;&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”AspNetCookbook” Namespace=”AspNetCookbook”&lt;br /&gt;Assembly=”codeVB” %&amp;gt;&lt;br /&gt;...&lt;br /&gt;&amp;lt;form id=”Form1” method=”post” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;AspNetCookbook:code0301vb id=”code0301vb1” runat=”server” /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;br /&gt;Note that in Visual Studio .NET, a default namespace with the same name as the project&lt;br /&gt;is automatically prefixed to all Visual Basic class names.This is a frequent source of confusion&lt;br /&gt;and is inconsistent with how default namespaces are handled in C#, where they&lt;br /&gt;are inserted into each class file as a visible namespace.You can turn off this default&lt;br /&gt;behavior by setting the default namespace to an empty string in the Project Properties&lt;br /&gt;dialog box.You can determine the full namespace of a class by using the ILDASM.EXE&lt;br /&gt;command-line tool on the generated assembly, or by going into the class view utility in&lt;br /&gt;Visual Studio .NET.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-8518868446219985346?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/8518868446219985346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=8518868446219985346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8518868446219985346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/8518868446219985346'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/declaring-simple-custom-control.html' title='Declaring a Simple Custom Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-2707559455590615783</id><published>2008-09-11T17:14:00.000+05:30</published><updated>2008-09-11T17:16:44.838+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Late-Bound User Control'/><title type='text'>Programmatically Accessing Properties of a Late-Bound User Control</title><content type='html'>In this example, you have a simple greeting User Control that exposes two properties&lt;br /&gt;and a method.You set one property using late binding and the other property using&lt;br /&gt;reflection.You then invoke the method using reflection.The User Control uses these&lt;br /&gt;properties to display a Label that holds a combination of these values.The code for the&lt;br /&gt;User Control is available from this book’s support Web site.When you declare the User&lt;br /&gt;Control on the page, you also set its username property declaratively—this property will&lt;br /&gt;be overridden at runtime by the code in Page_Load().&lt;br /&gt;&lt;br /&gt;The ASPX page:&lt;br /&gt;&amp;lt;form id=”Test” method=”post” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;uc1:Recipe0208vb id=”Recipe0208vb1” runat=”server”&lt;br /&gt;username=”Steve”&amp;gt;&amp;lt;/uc1:Recipe0208vb&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;br /&gt;In &amp;lt;script runat=”server” /&amp;gt; block or codebehind:&lt;br /&gt;Protected Recipe0208vb1 As Object&lt;br /&gt;Private Sub Page_Load(ByVal sender As System.Object, _&lt;br /&gt;ByVal e As System.EventArgs) Handles MyBase.Load&lt;br /&gt;‘Late binding call will override declarative setting&lt;br /&gt;‘Only works in VB, not C#&lt;br /&gt;Recipe0208vb1.UserName = “Rob”&lt;br /&gt;‘Reflection&lt;br /&gt;Dim myControl As Control = Page.FindControl(“Recipe0208vb1”)&lt;br /&gt;Dim myControlType As Type = myControl.GetType()&lt;br /&gt;Dim GreetingProperty As PropertyInfo =&lt;br /&gt;myControlType.GetProperty(“Greeting”)&lt;br /&gt;GreetingProperty.SetValue(myControl, “Guten Tag, “, Nothing)&lt;br /&gt;Dim MessageMethod As MethodInfo = myControlType.GetMethod(“AddMessage”)&lt;br /&gt;Dim Params() As Object = New Object()&lt;br /&gt;{“This message was added using reflection!”}&lt;br /&gt;MessageMethod.Invoke(myControl, Params)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;There are two ways to do this.The first one only works in Visual Basic and uses late binding.&lt;br /&gt;It works only when Option Strict is turned off, and allows variables declared as&lt;br /&gt;Object to use methods and properties that are not known at compile time. In general, it&lt;br /&gt;is not a good idea to use late binding if you can avoid it. However, one of the advantages&lt;br /&gt;of VB over C# is that it supports late binding, which provides a much simpler mechanism&lt;br /&gt;than reflection for tasks like the one described in this section.&lt;br /&gt;The second technique uses a process called reflection, which uses classes found in the&lt;br /&gt;System.Reflection namespace.The net effect is the same as with late binding, but the&lt;br /&gt;calls are much more explicit, and there is a lot more code. Because reflection is built into&lt;br /&gt;the .NET Framework, it will work with any .NET language.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2707559455590615783?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2707559455590615783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2707559455590615783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2707559455590615783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2707559455590615783'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/programmatically-accessing-properties.html' title='Programmatically Accessing Properties of a Late-Bound User Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-2583638351736293063</id><published>2008-09-11T17:12:00.000+05:30</published><updated>2008-09-11T17:14:48.039+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sharing User Controls'/><title type='text'>Sharing User Controls Across Application Domains</title><content type='html'>By design, User Controls are inaccessible outside of the application domain in which&lt;br /&gt;they reside.This is for security reasons. However, this can be a limitation if you want to&lt;br /&gt;share User Controls across several applications on a server. A fairly straightforward&lt;br /&gt;workaround exists, which involves setting up a virtual directory within each application&lt;br /&gt;that needs to use the User Controls, and mapping that virtual directory to a single physical&lt;br /&gt;directory containing the User Controls.This solution is better than simply copying&lt;br /&gt;the User Controls from application to application, because that would quickly turn into&lt;br /&gt;a maintenance nightmare.&lt;br /&gt;&lt;br /&gt;These steps were developed by readers of AspAlliance.com, and were first published&lt;br /&gt;in the article listed at the end of this section.&lt;br /&gt;1. Create a Web application project to hold the User Controls, and place the shared&lt;br /&gt;User Controls in this project.&lt;br /&gt;2. Create a virtual directory in each application that needs to use these shared User&lt;br /&gt;Controls.This is done in the IIS manager by right-clicking on the application and&lt;br /&gt;choosing New,Virtual Directory. Browse to the folder created for the Web application&lt;br /&gt;in Step 1, and name the directory the same as that folder.&lt;br /&gt;3. Create a reference from each application that needs the shared controls to the&lt;br /&gt;shared controls.This is done in Visual Studio .NET from within the Solution&lt;br /&gt;Explorer by right-clicking and choosing Add Reference. Browse to the bin folder&lt;br /&gt;of the project created in Step 1 and select the DLL from that folder. (It should&lt;br /&gt;have the same name as the project by default.)&lt;br /&gt;4. Drag-and-drop will not work for these shared User Controls in VS.NET. Instead,&lt;br /&gt;you must manually type the &amp;lt;%@ Register %&amp;gt; directive and specify the Src of the&lt;br /&gt;User Control, referring to the virtual directory you set up&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-2583638351736293063?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/2583638351736293063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=2583638351736293063' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2583638351736293063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/2583638351736293063'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/sharing-user-controls-across.html' title='Sharing User Controls Across Application Domains'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-1242279829823080581</id><published>2008-09-08T22:58:00.000+05:30</published><updated>2008-09-08T23:00:01.269+05:30</updated><title type='text'>Raising Events from a User Control</title><content type='html'>User Controls support events using the same syntax as other classes in the .NET&lt;br /&gt;Framework. Simply declare the event using the following syntax.In the User Control’s &amp;lt;script runat=”server” /&amp;gt; block or codebehind:&lt;br /&gt;Public Event MultipleReached(ByVal sender As Object, ByVal e As EventArgs)&lt;br /&gt;Public Overridable Sub OnMultipleReached(ByVal e As EventArgs)&lt;br /&gt;RaiseEvent MultipleReached(Me, e)&lt;br /&gt;End Sub&lt;br /&gt;The page can wire up the event by specifying a function for the OnMultipleReached&lt;br /&gt;attribute of the User Control, as follows.The ASPX page:&lt;br /&gt;&amp;lt;uc1:Recipe0206vb id=”Recipe0206vb1” runat=”server” Multiple=”5”&lt;br /&gt;OnMultipleReached=”MultipleReached”&amp;gt;&amp;lt;/uc1:Recipe0206vb&amp;gt;&lt;br /&gt;The User Control needs to raise the event by calling OnMultipleReached, which in this&lt;br /&gt;case it does every Nth time a counter is incremented.&lt;br /&gt;In the User Control’s &amp;lt;script runat=”server” /&amp;gt; block or codebehind:&lt;br /&gt;&lt;br /&gt;‘ if number of hits is a multiple of Multiple, raise event&lt;br /&gt;If Application(“count”) Mod Multiple = 0 Then&lt;br /&gt;OnMultipleReached(EventArgs.Empty)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Finally, in the page, you can specify which action to take in response to the event that&lt;br /&gt;the event handler function specified.&lt;br /&gt;In &amp;lt;script runat=”server” /&amp;gt; block or codebehind:&lt;br /&gt;Sub MultipleReached(ByVal sender As Object, ByVal e As EventArgs)&lt;br /&gt;Message.Text=”Congratulations! You were the 5th visitor!”&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The syntax for raising and handling events is quite different for C# than for VB.NET.&lt;br /&gt;The C# version of this technique is available from this book’s Web site.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-1242279829823080581?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/1242279829823080581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=1242279829823080581' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1242279829823080581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/1242279829823080581'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/raising-events-from-user-control.html' title='Raising Events from a User Control'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-7456721499618669874</id><published>2008-09-08T22:52:00.000+05:30</published><updated>2008-09-08T22:58:45.058+05:30</updated><title type='text'>Dynamically Adding User Controls to a Web Form</title><content type='html'>You simply load the User Control into a Control object and add it to the page (or&lt;br /&gt;other control inherited from System.Web.UI.Control). In &amp;lt;script runat=”server”&amp;gt;&lt;br /&gt;or codebehind:&lt;br /&gt;Sub Page_Load(sender as object, e as EventArgs)&lt;br /&gt;Dim sampleControl as Control = LoadControl(“recipe0201vb.ascx”)&lt;br /&gt;Controls.Add(sampleControl)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;You can also add an @ Reference directive at the top of the page to tell ASP.NET to&lt;br /&gt;dynamically compile and link the control at runtime. In the ASPX page:&lt;br /&gt;&amp;lt;%@ Reference Control=”recipe0201vb.ascx” %&amp;gt;&lt;br /&gt;&lt;br /&gt;The LoadControl function takes the virtual path to the User Control (specified as the&lt;br /&gt;parameter) and returns a Control object.This object can then be loaded onto the page&lt;br /&gt;with Controls.Add(control As System.Web.UI.Control).The Controls.Add function&lt;br /&gt;is also a member of any other control that inherits from System.Web.UI.Control.&lt;br /&gt;This technique can allow you to dynamically create your entire Web site.The&lt;br /&gt;IBuySpy portal sample application makes extensive use of this technique.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-7456721499618669874?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/7456721499618669874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=7456721499618669874' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7456721499618669874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/7456721499618669874'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/dynamically-adding-user-controls-to-web_08.html' title='Dynamically Adding User Controls to a Web Form'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-3819964493422289171</id><published>2008-09-01T13:14:00.004+05:30</published><updated>2008-09-01T23:27:44.228+05:30</updated><title type='text'>Partial Page Output Caching in ASP.NET</title><content type='html'>&amp;lt;%@ OutputCache Duration=”60” VaryByParam=”none” %&amp;gt;&lt;br /&gt;&amp;lt;script runat=”server”&amp;gt;&lt;br /&gt;Sub Page_Load(sender As Object, e As EventArgs)&lt;br /&gt;timestamp.Text = DateTime.Now.ToString()&lt;br /&gt;End Sub&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;asp:Label id=”timestamp” runat=”server” /&amp;gt;&lt;br /&gt;Caching the entire contents of a page is not always desirable. Examples include:&lt;br /&gt;n An application that executes per requested business logic&lt;br /&gt;n An application that displays user-specific content (personalization)&lt;br /&gt;Examples such as these are bad candidates for page output caching because the content&lt;br /&gt;can be reused only by the same user. Good candidates for partial page output caching&lt;br /&gt;include any dynamically generated content shared by all users, such as a menu or content&lt;br /&gt;served from a database.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-3819964493422289171?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/3819964493422289171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=3819964493422289171' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3819964493422289171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/3819964493422289171'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/partial-page-output-caching-in-aspnet.html' title='Partial Page Output Caching in ASP.NET'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-4892207866060216940</id><published>2008-09-01T13:14:00.003+05:30</published><updated>2008-09-01T23:26:42.105+05:30</updated><title type='text'>Dynamically Adding User Controls to a Web Form in ASP.NET</title><content type='html'>You simply load the User Control into a Control object and add it to the page (or&lt;br /&gt;other control inherited from System.Web.UI.Control). In &amp;lt;script runat=”server”&amp;gt;&lt;br /&gt;or codebehind:&lt;br /&gt;Sub Page_Load(sender as object, e as EventArgs)&lt;br /&gt;Dim sampleControl as Control = LoadControl(“codevb.ascx”)&lt;br /&gt;Controls.Add(sampleControl)&lt;br /&gt;End Sub&lt;br /&gt;You can also add an @ Reference directive at the top of the page to tell ASP.NET to&lt;br /&gt;dynamically compile and link the control at runtime. In the ASPX page:&lt;br /&gt;&amp;lt;%@ Reference Control=”codevb.ascx” %&amp;gt;&lt;br /&gt;&lt;br /&gt;The LoadControl function takes the virtual path to the User Control (specified as the&lt;br /&gt;parameter) and returns a Control object.This object can then be loaded onto the page&lt;br /&gt;with Controls.Add(control As System.Web.UI.Control).The Controls.Add function&lt;br /&gt;is also a member of any other control that inherits from System.Web.UI.Control.&lt;br /&gt;This technique can allow you to dynamically create your entire Web site.The&lt;br /&gt;IBuySpy portal sample application makes extensive use of this technique.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-4892207866060216940?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/4892207866060216940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=4892207866060216940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4892207866060216940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/4892207866060216940'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/dynamically-adding-user-controls-to-web.html' title='Dynamically Adding User Controls to a Web Form in ASP.NET'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-5016224306732673895</id><published>2008-09-01T13:13:00.001+05:30</published><updated>2008-09-01T23:29:01.129+05:30</updated><title type='text'>Getting and Setting User Control Properties in ASP.NET</title><content type='html'>User Control public properties can be set declaratively or programmatically from the&lt;br /&gt;page that contains them.Their values can also be read and used by the containing page.&lt;br /&gt;Full-property declaration should be used as a best practice, but for quick-and-dirty work,&lt;br /&gt;you might use public variables instead.&lt;br /&gt;The User Control (code0203vb.ascx) is as follows:&lt;br /&gt;&amp;lt;%@ Control Language=”vb” %&amp;gt;&lt;br /&gt;&amp;lt;script runat=”server”&amp;gt;&lt;br /&gt;Private _title As String&lt;br /&gt;Private _author As String&lt;br /&gt;Private _renderDate As DateTime = System.DateTime.Now&lt;br /&gt;Public Property Title() As String&lt;br /&gt;Get&lt;br /&gt;Return _title&lt;br /&gt;End Get&lt;br /&gt;Set&lt;br /&gt;_title = value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Public Property Author() As String&lt;br /&gt;Get&lt;br /&gt;Return _author&lt;br /&gt;End Get&lt;br /&gt;Set&lt;br /&gt;_author = value&lt;br /&gt;End Set&lt;br /&gt;End Property&lt;br /&gt;Public ReadOnly Property RenderDate() As DateTime&lt;br /&gt;Get&lt;br /&gt;Return _renderDate&lt;br /&gt;End Get&lt;br /&gt;End Property&lt;br /&gt;Private Sub Page_Load(sender As Object, e As EventArgs)&lt;br /&gt;TitleLabel.Text = Title&lt;br /&gt;AuthorLabel.Text = Author&lt;br /&gt;End Sub&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;h1&amp;gt;&amp;lt;asp:Label id=”TitleLabel” runat=”server” /&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;&amp;lt;h3&amp;gt;&amp;lt;asp:Label id=”AuthorLabel” runat=”server” /&amp;gt;&lt;br /&gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;This User Control is for a header of a story. It includes input parameters for the title and&lt;br /&gt;author of the story. It also exposes a readonly property for RenderDate that the calling&lt;br /&gt;page can use if it chooses to do so.The following page uses this control. It demonstrates&lt;br /&gt;how to set its Title property declaratively (in the HTML tag for the control) and how&lt;br /&gt;to set its Author property programmatically. It also reads the RenderDate and displays it&lt;br /&gt;in a Label.The ASPX page (code0203vb.aspx) is as follows:&lt;br /&gt;&amp;lt;%@ Page Language=”VB” %&amp;gt;&lt;br /&gt;&amp;lt;%@ Register TagPrefix=”uc1” TagName=”header” Src=”code0203vb.ascx” %&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN” &amp;gt;&lt;br /&gt;&amp;lt;HTML&amp;gt;&lt;br /&gt;&amp;lt;HEAD&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;User Controls&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;Script Runat=”Server”&amp;gt;&lt;br /&gt;Private Sub Page_Load(sender As Object, e As System.EventArgs)&lt;br /&gt;header1.Author = “Snoopy”&lt;br /&gt;FooterLabel.Text = “Rendered “ + header1.RenderDate&lt;br /&gt;End Sub ‘Page_Load&lt;br /&gt;&amp;lt;/Script&amp;gt;&lt;br /&gt;&amp;lt;/HEAD&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form id=”dependingdropdowns” method=”post” runat=”server”&amp;gt;&lt;br /&gt;&amp;lt;uc1:header id=”header1” runat=”server”&lt;br /&gt;Title=”A Tale of Mystery”&amp;gt;&amp;lt;/uc1:header&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;It was a dark and stormy night.&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;hr /&amp;gt;&lt;br /&gt;&amp;lt;asp:Label ID=”FooterLabel” Runat=”server” /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/HTML&amp;gt;&lt;br /&gt;&lt;br /&gt;Note: that these examples do not use codebehind files, so all class members are available&lt;br /&gt;locally. It is sometimes necessary to use reflection to access properties of User Controls&lt;br /&gt;that do not use codebehind from pages that do use codebehind.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7926983505765515035-5016224306732673895?l=aspdotnetslackers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetslackers.blogspot.com/feeds/5016224306732673895/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7926983505765515035&amp;postID=5016224306732673895' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5016224306732673895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7926983505765515035/posts/default/5016224306732673895'/><link rel='alternate' type='text/html' href='http://aspdotnetslackers.blogspot.com/2008/09/getting-and-setting-user-control.html' title='Getting and Setting User Control Properties in ASP.NET'/><author><name>satish</name><uri>http://www.blogger.com/profile/11104095808954112849</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-7926983505765515035.post-5322380510609133775</id><published>2008-09-01T13:12:00.001+05:30</published><updated>2008-09-01T13:12:54.855+05:30</updated><title type='text'>Adding a User Control to a Web Form in ASP.NET</title><content type='html'>You must first register the User Control on the page before you can insert it like a regular&lt;br /&gt;control. At the top of the ASPX page, add the following:&lt;br /&gt;&amp;lt;
