<?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:blogger='http://schemas.google.com/blogger/2008' 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-1673758462878856675</id><updated>2024-09-21T20:14:25.713-07:00</updated><title type='text'>ASP.NET Blogs</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspblogsbyrex.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1673758462878856675/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://aspblogsbyrex.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Prayerlin Rex</name><uri>http://www.blogger.com/profile/06746067590019418051</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGRRJSVcxRCjgOBPg9vbvo27IMN-NIEIr8jrt6_8sP_3BFsSJS6p4dYFHyCyuI_iDWg73F1DXQ55dBSM0FvrDf_9IXocx1GxRJFg1kJCy8s1J4Z1hFTOBsVukQiaB2qzw/s220/images.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1673758462878856675.post-7102191981134792733</id><published>2010-10-20T00:34:00.000-07:00</published><updated>2010-10-20T00:34:08.688-07:00</updated><title type='text'>Ajax Call in ASP.NET</title><content type='html'>Ajax Call in ASP.NET :&lt;br /&gt;
&lt;br /&gt;
what is Ajax:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ajax is shorthand for Asynchronous JavaScript and XML is a group of interrelated web development techniques used on the client-side to create interactive web applications. With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page &lt;br /&gt;
&lt;br /&gt;
Example :&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In&amp;nbsp; design page we have to add the following things&lt;br /&gt;
&lt;br /&gt;
&amp;lt;asp:TextBox ID=&quot;txtname&quot; runat=&quot;server&quot; Enabled=&quot;False&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Width=&quot;171px&quot; SkinID=&quot;txt&quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;asp:Button ID=&quot;button1&quot; Text=&quot;Click&quot; runat=&quot;server&quot; onclick=&quot;welcome()&quot;&amp;nbsp; /&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;then you have to add the following script inside the script portion&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function welcome_Result(ResultString) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(ResultString);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function welcome() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var str = getElementById(&#39;&amp;lt;%= txtname.ClientID %&amp;gt;&#39;);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PageMethods.WelcomeMessage(str.value, welcome_Result);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Inside the Codebhind page we have to add the WebMethod for that we have to add the following namespace&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;using System.Web.Services;&lt;br /&gt;
&lt;br /&gt;
In side the web method we have to add a method . From Client side we call this method only .This method should be a static method. Then define the proper retun type .&lt;br /&gt;
&lt;br /&gt;
[WebMethod]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public static string WelcomeMessage(string UserName)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return &quot;Hai Welcome&quot;+UserName ;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
When you Click the the button it will show one alert message with the text whatever you enter in the  Textbox.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;</content><link rel='replies' type='application/atom+xml' href='http://aspblogsbyrex.blogspot.com/feeds/7102191981134792733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspblogsbyrex.blogspot.com/2010/10/ajax-call-in-aspnet.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1673758462878856675/posts/default/7102191981134792733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1673758462878856675/posts/default/7102191981134792733'/><link rel='alternate' type='text/html' href='http://aspblogsbyrex.blogspot.com/2010/10/ajax-call-in-aspnet.html' title='Ajax Call in ASP.NET'/><author><name>Prayerlin Rex</name><uri>http://www.blogger.com/profile/06746067590019418051</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGRRJSVcxRCjgOBPg9vbvo27IMN-NIEIr8jrt6_8sP_3BFsSJS6p4dYFHyCyuI_iDWg73F1DXQ55dBSM0FvrDf_9IXocx1GxRJFg1kJCy8s1J4Z1hFTOBsVukQiaB2qzw/s220/images.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1673758462878856675.post-9020760377669931998</id><published>2010-09-27T06:30:00.000-07:00</published><updated>2010-09-27T06:30:13.964-07:00</updated><title type='text'>Cookies in ASP.NET</title><content type='html'>&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Cookies :&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;               &lt;span style=&quot;font-size: medium;&quot;&gt;Web applications often need to track users between page requests. These applications need to ensure that the user making the fi rst request is the same user making subsequent requests. This type of common tracking is done with what are called cookies.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;              &lt;span style=&quot;font-size: medium;&quot;&gt;A &lt;i&gt;cookie &lt;/i&gt;is a small amount of data that you write to the client to be stored and then passed with requests to your site. You write persistent cookies to a text fi le on the client machine. These cookies are meant to survive the user shutting down the browser and reopening it at a later time. You can also write temporary cookies to the memory of the client’s browser. These cookies are used only during the given Web session. They are lost when the browser closes. Again, the most common use of cookies is to identify a single user as he or she visits multiple Web pages within your site. However, you can also use cookies to store state information or other user preferences.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;              &lt;span style=&quot;font-size: medium;&quot;&gt;Cookies are the most fl exible and reliable way of storing data on the client. However, users can delete cookies on their computers at any time. You can set cookies to have long expiration times but that does not stop users from deleting all their cookies and thus wiping out any settings you might have stored in them. In addition, cookies do not solve the issue of a user moving from computer to computer. In these cases, users’ preferences do not always go along with them. Therefore, if you allow a lot of personalization for users of your site, you need to allow them to log in and reset their cookies. Doing so should then reenable their &lt;/span&gt;customizations provided you have them stored elsewhere.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Reading and Writing Cookies :&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;                     &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;A Web application creates a cookie by sending it to the client as a header in an HTTP response. Of course, ASP.NET makes writing to and reading from the cookie collection a relatively straight forward task. To add a cookie to the cookies collection and have it written out to the browser, you call the &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;Response.Cookies.Add method. &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;The &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;Cookies &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;property of the &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;Page.Response &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;property is of the type &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;HttpCookieCollection&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;. You add instances of &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;HttpCookie &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;to this collection. The &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;HttpCookie &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;object simply contains a &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;Name &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;property and a &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;Value &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;property. The following code shows how you might add an item to the cookies collection:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies.Add(New HttpCookie(&quot;userId&quot;, userId))&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;            &lt;span style=&quot;font-size: medium;&quot;&gt;To retrieve a cookie sent back by the Web browser, you read the values in the &lt;i&gt;Request. Cookies collection&lt;/i&gt;. The following shows an example of this code:&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Request.Cookies(&quot;userId&quot;).Value&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;            &lt;span style=&quot;font-size: medium;&quot;&gt;As a larger example, the following sample code in a &lt;i&gt;Page_Load &lt;/i&gt;event handler demonstrates both defining and reading cookie values by setting a cookie named lastVisit to the current time. If the user already has the cookie set, the code displays in the &lt;i&gt;Label1 &lt;/i&gt;control the time the user last visited the page.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;//check if cookie exists, and display it if it does&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;if (Request.Cookies[&quot;lastVisit&quot;] != null)&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;//encode the cookie in case the cookie contains client-side script&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Label1.Text = Server.HtmlEncode(Request.Cookies[&quot;lastVisit&quot;].Value);&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Label1.Text = &quot;No value defined&quot;;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;//define the cookie for the next visit&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Value = DateTime.Now.ToString();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Expires = DateTime.Now.AddDays(1);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;                     &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;The first time the user visits the page in the previous example, the code displays “No value defi ned” because the cookie has not yet been set. However, if you refresh the page, it displays the time of the fi rst visit.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Note that the code sample defi nes the &lt;i&gt;Expires &lt;/i&gt;property for the cookie. You must defi ne the &lt;i&gt;Expires &lt;/i&gt;property and set it for the time period you would like the client to store the cookie if you want the cookie to persist between browser sessions. If you do not defi ne the &lt;i&gt;Expires &lt;/i&gt;property, the browser stores the cookie in memory and the cookie is lost if the user closes his or her browser. To delete a cookie, you overwrite the cookie and set an expiration date in the past. You cannot directly delete cookies because they are stored on the client’s computer.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Controlling Cookie Scope :&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;             &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Cookies should be specifi c to a given Web site’s domain or a directory within that domain.The information in cookies is typically specifi c to that site and often private. For this reason a browser should not send your cookie to another site. By default, browsers will not send your cookie to a Web site with a different host name (although, in the past, vulnerabilities in&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;browsers have allowed attackers to trick a browser into submitting another Web site’s cookie).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;span style=&quot;font-size: medium;&quot;&gt;You have control over a cookie’s scope. You can limit the scope to either a specifi c directory on your Web server or expand the scope to the entire domain. The scope of your cookie determines which pages have access to the information embedded in the cookie. If you limit the scope to a directory, only pages in that directory will have access to the cookie. You control cookie scope on a per-cookie basis. To limit the scope of a cookie to a directory, you&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;set the &lt;i&gt;Path &lt;/i&gt;property of the &lt;i&gt;HttpCookie &lt;/i&gt;class. The following shows sample code for doing just that:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Value = DateTime.Now.ToString();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Expires = DateTime.Now.AddDays(1);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Path = &quot;/MyApplication&quot;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;             &lt;span style=&quot;font-size: medium;&quot;&gt;With the scope limited to “/MyApplication”, the browser submits the cookie to any page in &lt;/span&gt;the /MyApplication folder. However, pages outside of this folder do not get the cookie, even if they are on the same server.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;To expand the scope of a cookie to an entire domain, set the &lt;i&gt;Domain &lt;/i&gt;property of the &lt;i&gt;HttpCookie &lt;/i&gt;class. The following code demonstrates:&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Value = DateTime.Now.ToString();&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Expires = DateTime.Now.AddDays(1);&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;lastVisit&quot;].Domain = &quot;contoso.com&quot;;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;              &lt;span style=&quot;font-size: medium;&quot;&gt;Setting the &lt;i&gt;Domain &lt;/i&gt;property to “&lt;i&gt;contoso.com&lt;/i&gt;” causes the browser to submit the cookie to any page in the &lt;i&gt;contoso.com &lt;/i&gt;domain. This might include those pages that belong to the sites &lt;i&gt;www.contoso.com&lt;/i&gt;, &lt;i&gt;intranet.contoso.com&lt;/i&gt;, or &lt;i&gt;private.contoso.com&lt;/i&gt;. Similarly, you can use the &lt;i&gt;Domain &lt;/i&gt;property to specify a full host name, limiting the cookie to a specific server.&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Storing Multiple Values in a Cookie :&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;              &lt;span style=&quot;font-size: medium;&quot;&gt;The size of your cookie is dependent on the browser. Each cookie can be up to a maximum of 4 KB in length. In addition, you can typically store up to 20 cookies per site. This should be more than sufficient for most sites. However, if you need to work around the 20-cookie limit, you can store multiple values in a single cookie by setting the given cookie’s name and its key value. The key value is usually not used when storing just a single value. However, if you need multiple values in a single named cookie, you can add multiple keys. The following code shows an example:&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;info&quot;][&quot;visit&quot;].Value = DateTime.Now.ToString();&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;info&quot;][&quot;firstName&quot;].Value = &quot;Tony&quot;;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;info&quot;][&quot;border&quot;].Value = &quot;blue&quot;;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Response.Cookies[&quot;info&quot;].Expires = DateTime.Now.AddDays(1);&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;             &lt;span style=&quot;font-size: medium;&quot;&gt;Running this code sends a single cookie to the Web browser. However, that cookie is parsed to form three values. ASP.NET then reads these three values back in when the cookie is submitted back to the server. The following shows the value sent to the Web browser:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;              &lt;span style=&quot;font-size: medium;&quot;&gt;Cookie properties, such as &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;i&gt;Expires&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;i&gt;Domain&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, and &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;i&gt;Path&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;, apply for all the values within a &lt;/span&gt;single cookie. You cannot control these at the individual key value. Rather, they are controlled at the cookie (or name) level. You can access the individual values of a cookie using &lt;i&gt;Request.Cookies &lt;/i&gt;in the same way you define the values (using both name and key).&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspblogsbyrex.blogspot.com/feeds/9020760377669931998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspblogsbyrex.blogspot.com/2010/09/cookies-in-aspnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1673758462878856675/posts/default/9020760377669931998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1673758462878856675/posts/default/9020760377669931998'/><link rel='alternate' type='text/html' href='http://aspblogsbyrex.blogspot.com/2010/09/cookies-in-aspnet.html' title='Cookies in ASP.NET'/><author><name>Prayerlin Rex</name><uri>http://www.blogger.com/profile/06746067590019418051</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGRRJSVcxRCjgOBPg9vbvo27IMN-NIEIr8jrt6_8sP_3BFsSJS6p4dYFHyCyuI_iDWg73F1DXQ55dBSM0FvrDf_9IXocx1GxRJFg1kJCy8s1J4Z1hFTOBsVukQiaB2qzw/s220/images.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1673758462878856675.post-51314579997447473</id><published>2010-09-27T00:29:00.000-07:00</published><updated>2010-09-27T00:29:04.140-07:00</updated><title type='text'>User Control in ASP.NET</title><content type='html'>&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;u&gt;&lt;b&gt;User Control in ASP.NET :&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Definition :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;A &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;user control &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;is a file you create that contains a set of other ASP.NET controls and code grouped together to provide common functionality. &lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;The user control can then be used on different pages within a Web site.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;User controls in ASP.NET are created as .ascx fi les. An .ascx fi le is similar to the Web page’s &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;.aspx fi le and can have its own code-behind page.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Create User Control :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Step 1: &lt;/b&gt;&lt;/span&gt; &lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;First&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Create a new Web site called &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;SampleUserControl&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;using your    C# programming language.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Step 2:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Add a user control to the site: Right-click the &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Web&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; site and choose Add New Item. In the Add New Item dialog box, select Web User Control. Name the user control &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;addressusercontrol.ascx&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Step 3:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Open the user control and add input elements for address, city, state, and zip code.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Your control markup should look similar to the following:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;            &lt;span style=&quot;font-size: x-small;&quot;&gt;Address&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;           &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;           &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt; asp:TextBox ID=”TextBoxAddress” runat=”server” Width=”275px”&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;                &lt;span style=&quot;font-size: x-small;&quot;&gt;Height=”80px” TextMode=”MultiLine”&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;             &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;div style=”width: 280px”&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;           &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;div style=”float: left; margin-right: 3px”&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;           &lt;span style=&quot;font-size: x-small;&quot;&gt;City&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;          &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;           &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;asp:TextBox ID=”TextBoxCity” runat=”server” Width=”150”&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;div style=”float: left; margin-right: 3px”&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;          &lt;span style=&quot;font-size: x-small;&quot;&gt;State&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;         &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;asp:TextBox ID=”TextBoxState” runat=”server” Width=”30”&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;div style=”float: left”&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;      &lt;span style=&quot;font-size: x-small;&quot;&gt;Zip&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;         &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt; br /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;             &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;asp:TextBox ID=”TextBoxZip” runat=”server” Width=”70”&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;           &lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;lt;asp:Button ID=”ButtonSave” runat=”server” Text=”Save” /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 4:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Open the code-behind fi le and add properties to expose the &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Text &lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;property of the user &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;control’s &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;TextBox &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;controls. Your code should look similar to the following:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;public string Address&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;get { return TextBoxAddress.Text; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;set { TextBoxAddress.Text = value; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;public string City&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;get { return TextBoxCity.Text; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;set { TextBoxCity.Text = value; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;public string State&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;get { return TextBoxState.Text; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;set { TextBoxState.Text = value; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;public string Zip&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;get { return TextBoxZip.Text; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;set { TextBoxZip.Text = value; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt; &lt;span style=&quot;font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 5:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Next, you will defi ne the event handler for the Save button. This event will raise an event to the host of the user control. Given that the user control already exposes properties for reading its values, the event will not pass them as an argument; it will simply raise a generic event.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;             &lt;span style=&quot;font-size: medium;&quot;&gt;If using C#, start by adding a delegate to the user control. Add the delegate to the code-behind file but outside the class. Your delegate should look as follows:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;public delegate void SaveButtonClickHandler(object sender, EventArgs e);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Next, add the event declaration to the user control’s code-behind class file. This codeshould read as follows:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;public event SaveButtonClickHandler SaveButtonClick;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Finally, add code to the button’s click event that raises this event. The following is an example:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;protected void ButtonSave_Click(object sender, EventArgs e)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-weight: normal; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;if (SaveButtonClick != null)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;SaveButtonClick(this, new EventArgs());&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 5:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;           &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Compile your code and make sure there are no errors.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Use the User Control on Web Page :&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 1: &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;                   &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Continue editing the project you created in the previous exercise. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 2: &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Open the Default.aspx page in Design view. While in Design view, drag  &lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;AddressUser-Control.ascx&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt; to the page from Solution Explorer.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Review the page’s source. Notice that you can initialize the control’s custom properties through markup.  The properties are also available in the Properties window when in Design view.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 3:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Add an event handler to trap the event fi red by the user control when a user clicks the Save button. Open the Default.aspx page’s code-behind file.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;           &lt;span style=&quot;font-size: medium;&quot;&gt;In C#, you need to fi rst add a method to the page. This method should have the same signature as the event exposed by the user control. You then need to wire up the event from the user control to the newly defi ned method. You can do this inside the page’s &lt;i&gt;Init &lt;/i&gt;method. &lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;The following code shows an example:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;protected void Page_Init(object sender, EventArgs e)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;     &lt;span style=&quot;font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;        &lt;span style=&quot;font-size: x-small;&quot;&gt;AddressUserControl1.SaveButtonClick += this.AddressSave_Click;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;     &lt;span style=&quot;font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;    &lt;span style=&quot;font-size: x-small;&quot;&gt;protected void AddressSave_Click(object sender, EventArgs e)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;     &lt;span style=&quot;font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;      &lt;span style=&quot;font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 4:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;You now need to add code to the intercepted event. For this example, this code will simply take the user’s input and write it out to the debug window. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;The following shows an example:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;   &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;protected void AddressSave_Click(object sender, EventArgs e)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;    &lt;span style=&quot;font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;       &lt;span style=&quot;font-size: x-small;&quot;&gt;System.Diagnostics.Debug.WriteLine(“Address: &quot; +&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;        &lt;span style=&quot;font-size: x-small;&quot;&gt;AddressUserControl1.Address +&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;        &lt;span style=&quot;font-size: x-small;&quot;&gt;&quot; City: &quot; + AddressUserControl1.City +&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;        &lt;span style=&quot;font-size: x-small;&quot;&gt;&quot; State: &quot; + AddressUserControl1.State +&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;        &lt;span style=&quot;font-size: x-small;&quot;&gt;&quot; Zip: &quot; + AddressUserControl1.Zip);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% rgb(230, 230, 255);&quot;&gt;    &lt;span style=&quot;font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% transparent;&quot;&gt;Step 5:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;                   &lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Finally, run the application in debug mode to view the results. (You must enable script debugging in your browser.) Enter address information in the user control. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;            &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Click the Save button. Return to Visual Studio and view the Output window to see the results of the trapped Save button’s event.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspblogsbyrex.blogspot.com/feeds/51314579997447473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspblogsbyrex.blogspot.com/2010/09/user-control-in-aspnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1673758462878856675/posts/default/51314579997447473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1673758462878856675/posts/default/51314579997447473'/><link rel='alternate' type='text/html' href='http://aspblogsbyrex.blogspot.com/2010/09/user-control-in-aspnet.html' title='User Control in ASP.NET'/><author><name>Prayerlin Rex</name><uri>http://www.blogger.com/profile/06746067590019418051</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='27' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGRRJSVcxRCjgOBPg9vbvo27IMN-NIEIr8jrt6_8sP_3BFsSJS6p4dYFHyCyuI_iDWg73F1DXQ55dBSM0FvrDf_9IXocx1GxRJFg1kJCy8s1J4Z1hFTOBsVukQiaB2qzw/s220/images.jpg'/></author><thr:total>0</thr:total></entry></feed>