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

<channel>
	<title>.toString() &#187; runat=&#8221;server&#8221;</title>
	<atom:link href="http://www.dottostring.com/tag/runatserver/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dottostring.com</link>
	<description>Programming is our passion</description>
	<lastBuildDate>Sun, 04 Oct 2009 15:57:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ASP.NET Tutorials &#8211; [Part 04] ASP.NET 3.5 Controls and Event Handlers III</title>
		<link>http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/</link>
		<comments>http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 23:15:18 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET Controls]]></category>
		<category><![CDATA[AssociatedControlID]]></category>
		<category><![CDATA[BackColor]]></category>
		<category><![CDATA[BorderColor]]></category>
		<category><![CDATA[BorderStyle]]></category>
		<category><![CDATA[BorderWidth]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[CssClass]]></category>
		<category><![CDATA[Encode]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[ForeColor]]></category>
		<category><![CDATA[Label]]></category>
		<category><![CDATA[Literal Control]]></category>
		<category><![CDATA[Microsofto Visual Studio 2008]]></category>
		<category><![CDATA[Mode]]></category>
		<category><![CDATA[PassThrough]]></category>
		<category><![CDATA[runat]]></category>
		<category><![CDATA[runat="server"]]></category>
		<category><![CDATA[Standard Control]]></category>
		<category><![CDATA[Style]]></category>
		<category><![CDATA[ToolTip]]></category>
		<category><![CDATA[Transform]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=250</guid>
		<description><![CDATA[In this Part we are working with some of the Standard Controls in Details.
Standard Controls
Standard controls contain controls which help the developers to perform useful operations for example displaying information, taking user input in a textbox, displaying a drop down box, ListBox and many more. we will take look at some of them in detail.
Label [...]]]></description>
			<content:encoded><![CDATA[<p>In this Part we are working with some of the Standard Controls in Details.</p>
<h3>Standard Controls</h3>
<p>Standard controls contain controls which help the developers to perform useful operations for example displaying information, taking user input in a textbox, displaying a drop down box, ListBox and many more. we will take look at some of them in detail.</p>
<h4><span style="color: #000080;">Label Control</span></h4>
<p>label control is used when you need to dynamically display/change data on the webpage. we already saw a sample code in the last part (part 03) which changed text of the label dynamically on button&#8217;s click and TextBox&#8217;s TextChanged Event. There are plenty of Properties with which we play around with.</p>
<div id="attachment_251" class="wp-caption aligncenter" style="width: 204px"><a href="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-property-panel.jpg"><img class="size-medium wp-image-251" title="ASP.NET Standard Controls - Label - Property Panel" src="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-property-panel-194x300.jpg" alt="ASP.NET Standard Controls - Label - Property Panel" width="194" height="300" /></a><p class="wp-caption-text">ASP.NET Standard Controls - Label - Property Panel</p></div>
<p>following are some of the most used properties witha  brief description</p>
<ul>
<li><strong>BackColor &#8211; </strong>sets the color of the background of the label control</li>
<li><strong>BorderColor &#8211; </strong>sets the color of the border of the label control</li>
<li><strong>BorderStyle &#8211; </strong>lets you set the style of the border e.g. <strong>NotSet, None, Dotted, Dashed, Solid, Double, Groove, Ridge, Inset, and Outset.</strong></li>
<li><strong>BorderWidth &#8211; </strong>lets you set the width of the border</li>
<li><strong>CssClass -</strong>lets you set CSS class for label.</li>
<li><strong>Font &#8211; </strong>lets you configure various font properties e.g <strong>Bold, Italic, Name, Names</strong>, <strong>Overline, Size, Strikeout, Underline</strong></li>
<li><strong>ForeColor &#8211; </strong>lets you<strong> </strong>set the color of the content of the label.</li>
<li><strong>ToolTip &#8211; </strong>lets you set the tool tip for the label control.</li>
<li><strong>Style &#8211; </strong>lets you set inline style attribute for the label control.</li>
</ul>
<p>now lets have a look at a sample which illustrates the use of these properties.</p>
<pre name="code" class="html">&lt;%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;[.toString()] Standard Controls - http://dottostring.com&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:Label ID="Label1"
            runat="server"
            Text="label text goes here"
            BackColor="#FF9966"
            BorderColor="Black"
            BorderStyle="Double"
            BorderWidth="2px"
            Font-Bold="True"
            Font-Italic="True"&gt;
            &lt;/asp:Label&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<ul>
<li>Run (F5) your website and this is what you will get:</li>
</ul>
<div id="attachment_258" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration.jpg"><img class="size-medium wp-image-258" title="ASP.NET Standard Controls - Label - Properties Demonstration" src="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration-300x225.jpg" alt="ASP.NET Standard Controls - Label - Properties Demonstration" width="300" height="225" /></a><p class="wp-caption-text">ASP.NET Standard Controls - Label - Properties Demonstration</p></div>
<p>Labels are frequently used as the labels next to textbox fields in order to identify the information to be entered in those fields.  In order to associate a Label to a TextBox, Label has a property <strong>AssociatedControlID</strong>, setting this property doesn&#8217;t change anything as far as the display is concerned however when the label is clicked by the user it automatically takes the focus to the associated control.</p>
<p>Here is another sample which illustrates the use of <strong>AssociatedControlID </strong>and <strong>CssClass </strong>attributes.</p>
<pre name="code" class="html">&lt;%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;[.toString()] Standard Controls - http://www.dottostring.com&lt;/title&gt;
    &lt;style type="text/css"&gt;
        .LabelStyle {
            font-family: "Trebuchet MS";
            font-size: medium;
            font-weight: bold;
            color: #800000;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div &gt;
        &lt;asp:Label ID="Label1"
            runat="server"
            Text="label text goes here"
            BackColor="#FF9966"
            BorderColor="Black"
            BorderStyle="Double"
            BorderWidth="2px"
            Font-Bold="True"
            Font-Italic="True"&gt;
            &lt;/asp:Label&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;asp:Label
            ID="lblProductName"
            runat="server"
            AssociatedControlID="txtProductName"
            Text="Product Name"
            CssClass="LabelStyle"&gt;
            &lt;/asp:Label&gt;
        &lt;br /&gt;
        &lt;asp:TextBox
            ID="txtProductName"
            runat="server"&gt;
            &lt;/asp:TextBox&gt;
        &lt;br /&gt;
        &lt;asp:Label
            ID="lblProductCode"
            runat="server"
            AssociatedControlID="txtProductCode"
            Text="Product Code"
            CssClass="LabelStyle"&gt;
            &lt;/asp:Label&gt;
        &lt;br /&gt;
        &lt;asp:TextBox
            ID="txtProductCode"
            runat="server"&gt;
            &lt;/asp:TextBox&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<ul>
<li>Run(F5) the website and see the results.</li>
</ul>
<div id="attachment_259" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration-ii.jpg"><img class="size-medium wp-image-259" title="ASP.NET Standard Controls - Label - Properties Demonstration II" src="http://www.dottostring.com/wp-content/uploads/2009/01/aspnet-standard-controls-label-properties-demonstration-ii-300x225.jpg" alt="ASP.NET Standard Controls - Label - Properties Demonstration II" width="300" height="225" /></a><p class="wp-caption-text">ASP.NET Standard Controls - Label - Properties Demonstration II</p></div>
<h4><span style="color: #000080;">Literal Control</span></h4>
<p>Literal Control is almost the same as the Label Control except for the fact that Literal Control does not render its content inside the Span Tag, you can use it to display text or HTML content. it simply outputs contents assigned to it. Like for example lets say we need to dynamically update the title of the page, this can be done either by  placing a <strong>runat=&#8221;server&#8221; </strong> and  <strong>ID </strong>attributes to the Title Tag and then modify it from the server side or we can simply place a <strong>Literal Control </strong>in the Title Tag and then assign the desired title text to the literal control from the server.</p>
<p>Literal Control possess a useful property called <strong>Mode, </strong>which can be set to one of the following properties.</p>
<ul>
<li><strong>PassThrough &#8211; </strong>Everything assigned to the Text Property is rendered as it is to the browser. for example <em>&#8220;&lt;b&gt;&lt;i&gt;dottostring.com&lt;/i&gt;&lt;/b&gt;&#8221; </em> will print <em><strong>dottostring </strong></em>(in bold and italic)</li>
<li><strong>Transform &#8211; </strong>This will remove all the content from the Text Property of the Literal Control which is not supported by the browser/device it is rendering to. In case of HTML Browser this acts just like <strong>PassThrough</strong></li>
<li><strong>Encode &#8211; </strong>This will encode the all the tag so that they are displayed as it is to the viewer. for example <em>&#8220;&lt;b&gt;&lt;i&gt;dottostring.com&lt;/i&gt;&lt;/b&gt;&#8221; </em> will print &lt;b&gt;&lt;i&gt;dottostring.com&lt;/i&gt;&lt;/b&gt; to the user interface.</li>
</ul>
<p>as we dont have any span tag in the literal control rendered output, therefore we cannot apply any sort of formatting.</p>
<p>now lets look at some samples</p>
<ul>
<li>Add Two Literal Controls, one in the Title Tag and the other inside the body and name them <strong>lTitle </strong>and <strong>lContent </strong>respectively.</li>
<li>in the <strong>Page_Load </strong>Method add the following code.</li>
</ul>
<pre name="code" class="c#">protected void Page_Load(object sender, EventArgs e)
    {
        lTitle.Text = "[.toString()] Standard Controls - http://www.dottostring.com";
        lContent.Text = "&lt;b&gt;&lt;i&gt;dottostring&lt;/i&gt;&lt;/b&gt;";
    }</pre>
<ul>
<li>Run(F5) the application and notice the following results</li>
</ul>
<p> </p>
<div id="attachment_293" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-293" title="ASP.NET Standard Controls - Literal Control Demonstration" src="http://www.dottostring.com/wp-content/uploads/2009/02/aspnet-standard-controls-literal-control-demonstration-300x281.jpg" alt="ASP.NET Standard Controls - Literal Control Demonstration" width="300" height="281" /><p class="wp-caption-text">ASP.NET Standard Controls - Literal Control Demonstration</p></div>
<p>The Title of the page is what we set from the Page_Load Method dynamically and also we can see the other Literal Control which is rendered to display <strong>dottostring </strong> in below the two textboxes. also it is important to note that by Default the Mode Property for Literal Control is set to <strong>Transform</strong>, and since results are being redered to an HTML Browser, Transform and PassThrough will generate the same results, however when we change the <strong>IContent</strong>&#8217;s Mode Property to <strong>Encode </strong>it will also display the markup language on the user interface. effectively converting &#8220;&lt;&#8221; to &#8220;&amp;lt&#8221; and &#8220;&gt;&#8221; to &#8220;&amp;gt;&#8221;.</p>
<p> </p>
<div id="attachment_294" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-294" title="ASP.NET Standard Controls - Literal Control Demonstration - Mode=Encode" src="http://www.dottostring.com/wp-content/uploads/2009/02/aspnet-standard-controls-literal-control-demonstration-modeencode-300x281.jpg" alt="ASP.NET Standard Controls - Literal Control Demonstration - Mode=Encode" width="300" height="281" /><p class="wp-caption-text">ASP.NET Standard Controls - Literal Control Demonstration - Mode=Encode</p></div>
<p>we can clearly see the mark up language now. so Literal Control can be a very handy control in generating HTML content dynamically.</p>
<p>Thats it for this Part04, in this part we learned how to use some Standard Controls and what their important set of properties do. In the next part we will look at other Standard Controls which will enable us to make our interface much more user interactive.</p>
<ul>
<li>Thanks for visiting and waiting patiently for this part, I will be posting more regulary now, so keep in touch and don&#8217;t forget to leave comments/feedback</li>
<li><a rel="attachment wp-att-295" href="http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/dottostring-aspnet-tutorialspart04/">Download Source Code for Part04</a></li>
<li>Cheers !</li>
</ul>
<p>Previous Parts:</p>
<ul>
<li> <a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/" target="_self">ASP.NET Tutorials &#8211; [Part 01] A peek into ASP.NET and .NET Framework 3.5<br />
</a></li>
<li> <a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/" target="_self">ASP.NET Tutorials &#8211; [Part 02] ASP.NET 3.5 Controls and Event Handlers I<br />
</a></li>
<li> <a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/" target="_self">ASP.NET Tutorials &#8211; [Part 03] ASP.NET 3.5 Controls and Event Handlers II<br />
</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2009%2F02%2Faspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii%2F';
  addthis_title  = 'ASP.NET+Tutorials+%26%238211%3B+%5BPart+04%5D+ASP.NET+3.5+Controls+and+Event+Handlers+III';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ASP.NET Tutorials &#8211; [Part 03] ASP.NET 3.5 Controls and Event Handlers II</title>
		<link>http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/</link>
		<comments>http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 15:06:27 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET Controls]]></category>
		<category><![CDATA[Creating New Website]]></category>
		<category><![CDATA[Event Handlers]]></category>
		<category><![CDATA[Microsofto Visual Studio 2008]]></category>
		<category><![CDATA[On Click]]></category>
		<category><![CDATA[runat]]></category>
		<category><![CDATA[runat="server"]]></category>
		<category><![CDATA[Text Changed Event]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=225</guid>
		<description><![CDATA[In the last part (part 02) I gave you an overview of ASP.NET 3.5 Controls and their Event Handlers, in this part I will put forward some samples codes.
Creating an ASP.NET Website

Open Microsoft Visual Studio 2008
Create a new ASP.NET website (File &#8211; &#62; New &#8211; &#62; Website)



Provide the location and name for your website.
From the [...]]]></description>
			<content:encoded><![CDATA[<p>In the last part (part 02) I gave you an overview of ASP.NET 3.5 Controls and their Event Handlers, in this part I will put forward some samples codes.</p>
<h3>Creating an ASP.NET Website</h3>
<ul>
<li>Open Microsoft Visual Studio 2008</li>
<li>Create a new ASP.NET website (File &#8211; &gt; New &#8211; &gt; Website)</li>
</ul>
<p style="text-align: center;">
<div id="attachment_226" class="wp-caption aligncenter" style="width: 488px"><img class="size-full wp-image-226" title="My First Website - Create New Website" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-create-new-website.jpg" alt="My First Website - Create New Website" width="478" height="316" /><p class="wp-caption-text">My First Website - Create New Website</p></div>
<ul>
<li>Provide the location and name for your website.</li>
<li>From the Language drop down you can select the language of your choice (I will be using C# throughout all my articles).</li>
<li>Pressing OK, will create a website project for you and by default it already has a Default.aspx page added to it.</li>
</ul>
<p>Switch to Split View of the Default Page and drag and drop a Label, TextBox and Button Control on the interface such that it looks something like this.</p>
<div id="attachment_227" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-sample-default-page.jpg"><img class="size-medium wp-image-227" title="My First Website - Sample Default Page" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-sample-default-page-300x194.jpg" alt="My First Website - Sample Default Page" width="300" height="194" /></a><p class="wp-caption-text">My First Website - Sample Default Page</p></div>
<p>lets look at the declaration of these controls.</p>
<p>&lt;asp:Label ID=&#8221;lblmyLabel&#8221; runat=&#8221;server&#8221;&gt;&lt;/asp:Label&gt;<br />
&lt;asp:TextBox ID=&#8221;txtmyTextBox&#8221; runat=&#8221;server&#8221;&gt;&lt;/asp:TextBox&gt;<br />
&lt;asp:Button ID=&#8221;btnmyButton&#8221; runat=&#8221;server&#8221; Text=&#8221;Click&#8221; /&gt;</p>
<p>all of the ASP.NET Controls have the following characteristics</p>
<ul>
<li> Tag Element starting with <strong>asp:</strong> <em>( with the exception of HTML Controls )</em></li>
<li>Each tag (ASP.NET Control tag) has an attribute <strong>runat=&#8221;server&#8221;</strong> which indicates to the framework that this control needs to be rendered at the server side.<em> (HTML Controls can have this attribute only if you need to access it in the server side code)</em></li>
<li><strong>ID </strong>attribute in the declaration of the ASP.NET Control identifies it, once defined, these controls can be accessed on the server side with these IDs.(I have already given controls appropriate IDs)</li>
</ul>
<p>Now lets add a click event to the button we have on the page, to do that select the button and the look for <strong>Properties Panel</strong> on the right bottom of the VS Interface ( if you cannot see the properties panel, <strong>Press F4</strong>). everything you see in this panel are the properties of the control you have selected and you can modify them here. For now we are interested in adding a Click Event, Select  Events Tab in the properties panel.</p>
<div id="attachment_228" class="wp-caption aligncenter" style="width: 382px"><img class="size-full wp-image-228" title="My First Website - Properties Panel - Button Events" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-properties-panel-button-events.jpg" alt="My First Website - Properties Panel - Button Events" width="372" height="332" /><p class="wp-caption-text">My First Website - Properties Panel - Button Events</p></div>
<p>you can see there are number of Button events available, but by default no events is placed. To add an event, lets say Click Event, we need to double click the space in front of the Click Label, this will add a Button Click Event handler in the Code File of the Default.aspx. This is how your code-behind file for this page would look like with a Button Click Event Handler.</p>
<pre name="code" class="c#">using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnmyButton_Click(object sender, EventArgs e)
    {

    }
}</pre>
<p><strong>btnmyButton_Click </strong>Event will occur everytime when <strong>btnmyButton</strong> is clicked. now lets Append <strong>&#8220;Hello&#8221; </strong>to the Label (lblmyLabel) Text everytime this button is clicked.</p>
<pre name="code" class="c#">    protected void btnmyButton_Click(object sender, EventArgs e)
    {
        lblmyLabel.Text += "Hello ";
    }</pre>
<ul>
<li>Run (F5) the website and click on the Button more than one time and see what happens. (Note: for the very first time  a Message Box will appear once you Run (F5) your website asking whether to enable debugging or not, Press Yes/Ok)</li>
</ul>
<div id="attachment_233" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-button-click-event-handler-demonstration.jpg"><img class="size-medium wp-image-233" title="My First Website - Button Click Event Handler Demonstration" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-button-click-event-handler-demonstration-300x225.jpg" alt="My First Website - Button Click Event Handler Demonstration" width="300" height="225" /></a><p class="wp-caption-text">My First Website - Button Click Event Handler Demonstration</p></div>
<p>now this is how we can perform different kind of operations, for example manipulating certain information from a form to the database. similarly we have <strong>TextChanged </strong>Event available for the TextBox control, lets say we require that, whatever is written in the textbox is appended to the label whenever textbox loses focus, All we need to do is select mytxtTextBox control we dropped earlier on the page and add its TextChanged Event Handler like the way we added Button&#8217;s Click Event.</p>
<pre name="code" class="c#">using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnmyButton_Click(object sender, EventArgs e)
    {
        lblmyLabel.Text += "Hello ";
    }
    protected void txtmyTextBox_TextChanged(object sender, EventArgs e)
    {
        lblmyLabel.Text += txtmyTextBox.Text;
    }
}</pre>
<p>just the way on the click of the button there was a post back to the server so that text could be appended to the label, TextBoxes by default are set not to post back on any event, we have to explicitly enable post back by enabling <strong>AutoPostBack</strong> property of the<strong> txtmyTextBox.</strong></p>
<div id="attachment_236" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-properties-panel-autopostback-property.jpg"><img class="size-medium wp-image-236" title="My First Website - Properties Panel - AutoPostBack Property" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-properties-panel-autopostback-property-300x245.jpg" alt="My First Website - Properties Panel - AutoPostBack Property" width="300" height="245" /></a><p class="wp-caption-text">My First Website - Properties Panel - AutoPostBack Property</p></div>
<p>this will make the TextBox postback to the server on <strong>TextChanged </strong>Event.</p>
<ul>
<li>Now Run(F5) the website again</li>
<li>Enter some text in the textbox and click out side the textbox, this will make the textbox lose focus and subsequently will post back to the server and call the TextChanged Event Handler and our text will appended in the label above.</li>
</ul>
<div id="attachment_238" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-textboxs-textchanged-event-handler-demonstration.jpg"><img class="size-medium wp-image-238" title="My First Website - TextBox's TextChanged Event Handler Demonstration" src="http://www.dottostring.com/wp-content/uploads/2008/12/my-first-website-textboxs-textchanged-event-handler-demonstration-300x225.jpg" alt="My First Website - TextBox's TextChanged Event Handler Demonstration" width="300" height="225" /></a><p class="wp-caption-text">My First Website - TextBox&#39;s TextChanged Event Handler Demonstration</p></div>
<p>this brings us to the end of Part 03. In this part we learned How ASP.NET Controls and Event Handlers are used in ASP.NET Websites, in the upcoming parts we shall look into Controls in each Category in detail, discovering various properties and events associated with them.</p>
<ul>
<li>Thanks for Visiting, don&#8217;t forget to let us know how did this article helped you.</li>
<li><a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostring-aspnet-tutorialspart03.zip">Download Source Code  for Part 03</a></li>
<li>Cheers!</li>
</ul>
<p>Proceed to:</p>
<ul>
<li><a href="http://www.dottostring.com/2009/02/aspnet-tutorials-part-04-aspnet-35-controls-and-event-handlers-iii/" target="_self">ASP.NET Tutorials &#8211; [Part 04] ASP.NET 3.5 Controls and Event Handlers III<br />
	</a>
	</li>
</ul>
<p>Previous Parts:</p>
<ul>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-1-a-peek-into-aspnet-and-net-framework-3_5/" target="_self">ASP.NET Tutorials &#8211; [Part 01] A peek into ASP.NET and .NET Framework 3.5</a></li>
<li><a href="http://www.dottostring.com/2008/12/aspnet-tutorials-part-2-aspnet-35-controls-and-event-handlers-i/" target="_self">ASP.NET Tutorials &#8211; [Part 02] ASP.NET 3.5 Controls and Event Handlers I</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Faspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii%2F';
  addthis_title  = 'ASP.NET+Tutorials+%26%238211%3B+%5BPart+03%5D+ASP.NET+3.5+Controls+and+Event+Handlers+II';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/12/aspnet-tutorials-part-03-aspnet-35-controls-and-event-handlers-ii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
