<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Emad Mokhtar's Framework - ASP.NET</title>
    <link>http://www.emadmokhtar.com/</link>
    <description>Computer-Geek Life Style</description>
    <language>en-us</language>
    <copyright>Emad Mokhtar</copyright>
    <lastBuildDate>Tue, 20 Jul 2010 06:56:20 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>emadmokhtar@emadmokhtar.com</managingEditor>
    <webMaster>emadmokhtar@emadmokhtar.com</webMaster>
    <item>
      <trackback:ping>http://www.emadmokhtar.com/Trackback.aspx?guid=c09e6db9-081c-4c76-8e7b-be9b4f959399</trackback:ping>
      <pingback:server>http://www.emadmokhtar.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.emadmokhtar.com/PermaLink,guid,c09e6db9-081c-4c76-8e7b-be9b4f959399.aspx</pingback:target>
      <dc:creator>Emad Mokhtar</dc:creator>
      <wfw:comment>http://www.emadmokhtar.com/CommentView,guid,c09e6db9-081c-4c76-8e7b-be9b4f959399.aspx</wfw:comment>
      <wfw:commentRss>http://www.emadmokhtar.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c09e6db9-081c-4c76-8e7b-be9b4f959399</wfw:commentRss>
      <title>Client-side Validation in ASP.NET webforms by using jQuery</title>
      <guid isPermaLink="false">http://www.emadmokhtar.com/PermaLink,guid,c09e6db9-081c-4c76-8e7b-be9b4f959399.aspx</guid>
      <link>http://www.emadmokhtar.com/ClientsideValidationInASPNETWebformsByUsingJQuery.aspx</link>
      <pubDate>Tue, 20 Jul 2010 06:56:20 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img src="http://www.emadmokhtar.com/content/binary/JQuery_logo_color_onwhite.png" alt="JQuery_logo_color_onwhite.png" height="104" width="420"&gt;
&lt;/p&gt;
&lt;p&gt;
Hello folks, on July 9th 2010, I'd spoken on EgyGeeks online community about Client-side
Validation using jQuery in ASP.NET webforms, and I thought I'll share the session
as a blog post, so let's start
&lt;/p&gt;
&lt;h3&gt;Why using Client-side validation?
&lt;/h3&gt;
&lt;p&gt;
Web developers love to use Client-side validation to increase their web application
user experience "UX", to make web application feels like the desktop application,
and to reduce the round-trip to web server to validate the user inputs every time
he/she submit a page.
&lt;/p&gt;
&lt;h3&gt;Demo:
&lt;/h3&gt;
&lt;p&gt;
First of all I'm using one of the oldest and the first jQuery validation plugin called
validation, please take a look ot its documentation for more info. [&lt;a href="http://docs.jquery.com/Plugins/Validation" target="_blank" title="jQuery Validation Plugin Documentation"&gt;link&lt;/a&gt;]
&lt;/p&gt;
&lt;p&gt;
Let's create a simple ASP.NET page to apply some of validation rules on:
&lt;/p&gt;
&lt;pre class="brush: html;"&gt;First name:&lt;asp:textbox id="TxtFirstName" runat="server"&gt;&lt;/asp:textbox&gt;
&lt;br&gt;
&lt;br&gt;
Password:&lt;asp:textbox id="TxtPassword" runat="server" textmode="Password"&gt;&lt;/asp:textbox&gt;
&lt;br&gt;
Password Confirmation:&lt;asp:textbox id="TxtRePassword" runat="server" textmode="Password"&gt;&lt;/asp:textbox&gt;
&lt;br&gt;
&lt;br&gt;
Email Address:&lt;asp:textbox id="TxtEmail" runat="server"&gt;&lt;/asp:textbox&gt;
&lt;br&gt;
&lt;asp:button id="btnSubmit" runat="server" text="Submit"&gt;&lt;/asp:button&gt;
&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
Now let's write our jQuery code to apply some validation rules on this ASP.NET form,
but first make sure you create a link for jQuery .js file and the plugin validation.js
file into the aspx page or you can use the Microsoft CDN version {hosted on Microsoft
servers} " &lt;a href="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js"&gt;http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js&lt;/a&gt;"
"&lt;a href="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js"&gt;http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js&lt;/a&gt; ":
&lt;/p&gt;
&lt;pre class="brush: html;"&gt;    &lt;script type="text/javascript"&gt;
        $(document).ready(function () {
            $("#MainForm").validate({
                rules:
                {
                    TxtFirstName:
                    {
                        required: true,
                        rangelength: [3, 12]
                    },
                    TxtPassword:
                    {
                        required: true
                    },
                    TxtRePassword:
                    {
                        required: true,
                        equalTo: "#txtPassword"
                    },
                    TxtEmail:
                    {
                        required: true,
                        email: true
                    },
                }
            },
            messages:
                {
                    TxtFirstName:
                    {
                        required: "Please enter your first name",
                        rangelength: "Please enter minimum 3 characters and Maximum 12 character"
                    },
                    TxtRePassword:
                    {
                        required: "Please enter your password again",
                        equalTo: "The two password is not matching"
                    },
                    TxtEmail:
                    {
                        required: "Please enter your email address",
                        email: "Please enter valid email address"
                    }

                }
        });
    });
    &lt;/script&gt;
&lt;br&gt;
&lt;/pre&gt;
&lt;p&gt;
As you can see it's so simple and easy to apply these validation, like required rule,
which means this field is required field, and apply the email RegExp with email: true.
&lt;/p&gt;
&lt;p&gt;
The .validate() function takes 2 parameters {rules, messages}, rules is the validation
rules you want to apply, and message is the text message you want to appear to the
user if he doesn't apply your validation rules on his inputs, and BTW message is optional
{overload .validate() function} you can let the plugin display the default message
according to the rule itself, for example here I let the plugin display the default
message for TxtPassword Required rule.
&lt;/p&gt;
&lt;p&gt;
Note: please use ASP.NET 4 new feature {&lt;a href="http://www.emadmokhtar.com/ASPNET4WebformsNewFeatureClientIDMode.aspx" target="_blank" title="ClientIDMode"&gt;ClientIDMode&lt;/a&gt;},
or use &lt;span style="background: none repeat scroll 0% 0% yellow;"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt; txtFirstName.UniqueID &lt;span style="background: none repeat scroll 0% 0% yellow;"&gt;%&amp;gt;&lt;/span&gt; when
writing the Control ID inside jQuery script. 
&lt;/p&gt;
&lt;p&gt;
Please for more validation rules read the documentation I refer above.
&lt;/p&gt;
&lt;p xmlns="" class="zoundry_raven_tags"&gt;
&lt;!-- Tag links generated by Zoundry Raven. Do not manually edit. http://www.zoundryraven.com --&gt;
&lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Del.icio.us&lt;/span&gt; : &lt;a href="http://del.icio.us/tag/jQuery" class="ztag" rel="tag"&gt;jQuery&lt;/a&gt; &lt;a href="http://del.icio.us/tag/ASP.NET" class="ztag" rel="tag"&gt;ASP.NET&lt;/a&gt; &lt;a href="http://del.icio.us/tag/Valdation" class="ztag" rel="tag"&gt;Validation&lt;/a&gt;&lt;/span&gt; 
&lt;br&gt;
&lt;span class="ztags"&gt;&lt;span class="ztagspace"&gt;Technorati&lt;/span&gt; : &lt;a href="http://www.technorati.com/tag/jQuery" class="ztag" rel="tag"&gt;jQuery&lt;/a&gt; &lt;a href="http://www.technorati.com/tag/ASP.NET" class="ztag" rel="tag"&gt;ASP.NET&lt;/a&gt; &lt;a href="http://www.technorati.com/tag/Validation" class="ztag" rel="tag"&gt;Validation&lt;/a&gt;&lt;/span&gt; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.emadmokhtar.com/aggbug.ashx?id=c09e6db9-081c-4c76-8e7b-be9b4f959399" /&gt;
&lt;br /&gt;
&lt;hr /&gt;© Copyright, Emad Mokhtar</description>
      <comments>http://www.emadmokhtar.com/CommentView,guid,c09e6db9-081c-4c76-8e7b-be9b4f959399.aspx</comments>
      <category>ASP.NET</category>
      <category>jQuery</category>
      <category>Validation</category>
    </item>
    <item>
      <trackback:ping>http://www.emadmokhtar.com/Trackback.aspx?guid=4f75da89-76e7-4dc7-a0f7-7a867f5fa724</trackback:ping>
      <pingback:server>http://www.emadmokhtar.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.emadmokhtar.com/PermaLink,guid,4f75da89-76e7-4dc7-a0f7-7a867f5fa724.aspx</pingback:target>
      <dc:creator>Emad Mokhtar</dc:creator>
      <wfw:comment>http://www.emadmokhtar.com/CommentView,guid,4f75da89-76e7-4dc7-a0f7-7a867f5fa724.aspx</wfw:comment>
      <wfw:commentRss>http://www.emadmokhtar.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4f75da89-76e7-4dc7-a0f7-7a867f5fa724</wfw:commentRss>
      <title>ASP.NET 4 Validation Controls</title>
      <guid isPermaLink="false">http://www.emadmokhtar.com/PermaLink,guid,4f75da89-76e7-4dc7-a0f7-7a867f5fa724.aspx</guid>
      <link>http://www.emadmokhtar.com/ASPNET4ValidationControls.aspx</link>
      <pubDate>Mon, 21 Jun 2010 09:54:17 GMT</pubDate>
      <description>&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;Hello folks today I'm going
to review ASP.NET 4 validation controls in Visual Studio 2010; first let's explain
why we need validation on our web application first.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;strong&gt;Why do we need Validation
in our web application?&lt;/strong&gt;&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;For many reasons, I can't cover
all here, but I'll cover most important reasons, which are:&lt;/span&gt; 
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;Validate user input data: sometimes
you need to make sure user puts the correct information in correct field, or correct
type of information in its corresponding field.&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;Avoid &lt;a href="file:///C%7C/Users/Emad%20Mokhtar/Documents/20100416-Emad%20Mokhtar%27s%20Free%20Meeting%28598734590%29"&gt;XSS
"cross-site scripting"&lt;/a&gt;: one of way to avoid XSS from your web application is to
validate the inputs from unreasonable characters.&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;Avoid &lt;a href="http://en.wikipedia.org/wiki/SQL_injection"&gt;SQL
injection&lt;/a&gt;: validate the input parameters save your web application form SQL Injection
attacks.&lt;/span&gt; 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;strong&gt;Note: To build secure
web application, make sure Validation implemented on client-side and server-side.&lt;/strong&gt;&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;Microsoft ASP.NET did a great
job to make this easy task on web developer by implement both Server-Side and Client-Side
in ASP.NET validation controls; even if you want to implement other client-side framework
like jQuery or write your own client-side Javascript validation rules you can disable
the client-side validation function in ASP.NET validation control.&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;First let's examine the validation
controls that ASP.NET provides for us:&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.emadmokhtar.com/content/binary/062110_0954_ASPNET4Vali1.jpg" alt="" height="207" width="292"&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;strong&gt;ASP.NET Validation Controls:&lt;/strong&gt;&lt;/span&gt; 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;CompareValidator:&lt;/span&gt; this
control let you compare 2 user inputs, like make sure user puts the password twice
correctly.&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;CustomValidator:&lt;/span&gt; this
control let you build/write your own Validation rule, both Server-side and client-side.&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;RangeValidator:&lt;/span&gt; this
control validates the input parameters with specific range with maximum and minimum
value.&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;RegularExpressionValidator:&lt;/span&gt; this
control helps you implement a custom regular expression to validate the input data
against, like telephone number.&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;RequiredFieldValidator:&lt;/span&gt; this
control is to make sure user fill this field, like Username.&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;span style="color: red;"&gt;ValidationSummary:&lt;/span&gt; this
control displays the summary of all Validation info on the page, to make sure user
know what's wrong with his inputs.&lt;/span&gt; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;&lt;strong&gt;Tip: you can use those
Regular Expression cheat sheets to build your custom one. [&lt;a href="http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/"&gt;link&lt;/a&gt;][&lt;a href="http://regexlib.com/CheatSheet.aspx"&gt;link&lt;/a&gt;],
or use this Regular Expression builder web app [&lt;a href="http://gskinner.com/RegExr/"&gt;link&lt;/a&gt;]&lt;/strong&gt;&lt;/span&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;Second, let's build a sample
an ASP.NET web from and implement some validation controls:&lt;/span&gt; 
&lt;/p&gt;
&lt;pre class="brush: html;"&gt;First Name: 
&lt;asp:textbox id="TxtFirstName" runat="server"&gt;&lt;/asp:textbox&gt;
&lt;asp:requiredfieldvalidator id="RFVTxtFirstName" runat="server" errormessage="This field is required" controltovalidate="TxtFirstName"&gt;&lt;/asp:requiredfieldvalidator&gt;
&lt;/pre&gt;
&lt;ul style="margin-left: 63pt;"&gt;
&lt;li&gt;
&lt;span style="font-size: 10pt;"&gt;&lt;span style="font-family: Segoe UI;"&gt;Here we used RequiredFieldValidator
to make sure user input his First name on the TxtFirstName TextBox by adding&lt;/span&gt; &lt;span style="color: red;"&gt;&lt;span style="font-family: Consolas;"&gt;ControlToValidate&lt;span style="color: blue;"&gt;="TxtFirstName"&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family: Segoe UI; color: black;"&gt;attribute,
and customize the message will be display if there's validation error&lt;/span&gt; &lt;span style="font-family: Consolas;"&gt;ErrorMessage&lt;span style="color: blue;"&gt;="This
field is required"&lt;/span&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="brush: html;"&gt;Last Name: 
&lt;asp:textbox id="TxtLastName" runat="server"&gt;&lt;/asp:textbox&gt;
&lt;asp:regularexpressionvalidator id="REVLastName" runat="server" errormessage="please enter at least 3 charaters" controltovalidate="TxtLastName" validationexpression="[0-9a-zA-Z]{3,}"&gt;&lt;/asp:regularexpressionvalidator&gt;
&lt;/pre&gt;
&lt;ul style="margin-left: 63pt;"&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI; font-size: 10pt;"&gt;Here we used RegularExpressionValidator
to validate that user enter at least 3 characters in the Last name TextBox by add
this regular expression&lt;/span&gt; &lt;span style="font-family: Consolas;"&gt;&lt;span style="color: blue;"&gt;[0-9a-zA-Z]{3,}&lt;/span&gt;.&lt;/span&gt; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="brush: html;"&gt;Email Address: 
&lt;asp:textbox id="TxtEmail" runat="server"&gt;&lt;/asp:textbox&gt;
&lt;asp:regularexpressionvalidator id="REVEmail" runat="server" errormessage="please enter vaild email address" validationexpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" controltovalidate="TxtEmail"&gt;&lt;/asp:regularexpressionvalidator&gt;
&lt;/pre&gt;
&lt;ul style="margin-left: 63pt;"&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI;"&gt;And here another implementation for RegularExpressionValidator,
but this time to validate the user email address and here's the regulat expression
for Email address&lt;/span&gt; &lt;span style="font-family: Consolas;"&gt;&lt;span style="color: blue;"&gt;^([0-9a-zA-Z]([-.\w]*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$&lt;/span&gt;&lt;/span&gt; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="brush: html;"&gt;Age: 
&lt;asp:textbox id="TxtAge" runat="server"&gt;&lt;/asp:textbox&gt;
&lt;asp:rangevalidator id="RVAge" runat="server" errormessage="your age must be older than 13 years or younger than 85" minimumvalue="13" maximumvalue="85" type="String" controltovalidate="TxtAge"&gt;&lt;/asp:rangevalidator&gt;
&lt;/pre&gt;
&lt;ul style="margin-left: 63pt;"&gt;
&lt;li&gt;
&lt;span style="font-family: Segoe UI;"&gt;We implement RangValidator to make sure user
age is between 13 and 85 years old.&lt;br&gt;
&lt;/span&gt;
&lt;br&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: Segoe UI;"&gt;Finally, I built a sample webform to demonstrate
what ASP.NET Validation Controls can do, and here's the &lt;a href="http://emadmokhtar.com/Download/ValidationControlsDemo.zip"&gt;&lt;span style="color: blue; text-decoration: underline;"&gt;download
link&lt;/span&gt;&lt;/a&gt; &lt;/span&gt;&lt;img width="0" height="0" src="http://www.emadmokhtar.com/aggbug.ashx?id=4f75da89-76e7-4dc7-a0f7-7a867f5fa724" /&gt;
&lt;br /&gt;
&lt;hr /&gt;© Copyright, Emad Mokhtar</description>
      <comments>http://www.emadmokhtar.com/CommentView,guid,4f75da89-76e7-4dc7-a0f7-7a867f5fa724.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.emadmokhtar.com/Trackback.aspx?guid=a17dc236-97f0-4bc3-b39b-2c4ad8284a8b</trackback:ping>
      <pingback:server>http://www.emadmokhtar.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.emadmokhtar.com/PermaLink,guid,a17dc236-97f0-4bc3-b39b-2c4ad8284a8b.aspx</pingback:target>
      <dc:creator>Emad Mokhtar</dc:creator>
      <wfw:comment>http://www.emadmokhtar.com/CommentView,guid,a17dc236-97f0-4bc3-b39b-2c4ad8284a8b.aspx</wfw:comment>
      <wfw:commentRss>http://www.emadmokhtar.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a17dc236-97f0-4bc3-b39b-2c4ad8284a8b</wfw:commentRss>
      <title>ASP.NET 4 webforms new feature: ClientIDMode</title>
      <guid isPermaLink="false">http://www.emadmokhtar.com/PermaLink,guid,a17dc236-97f0-4bc3-b39b-2c4ad8284a8b.aspx</guid>
      <link>http://www.emadmokhtar.com/ASPNET4WebformsNewFeatureClientIDMode.aspx</link>
      <pubDate>Tue, 04 May 2010 18:17:52 GMT</pubDate>
      <description>&lt;p&gt;
Today we'll examine ClientIDMode the new feature of ASP.NET 4 which makes life easier
on developers when writing client-side scripting/code like javascript or jQuery. 
&lt;/p&gt;
&lt;h3&gt;ClientIDMode control property: 
&lt;/h3&gt;
&lt;p&gt;
You can assign ClientIDMode property for ASP.NET controls which is take 4 values 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
AutoID 
&lt;/li&gt;
&lt;li&gt;
Inherit 
&lt;/li&gt;
&lt;li&gt;
Predictable 
&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Static 
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.emadmokhtar.com/content/binary/050410_1817_ASPNET4webf1.jpg" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
And I'll demonstrate what the different between those 4 values. 
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Demo: 
&lt;/h3&gt;
&lt;p&gt;
We've simple ASP.NET 4 page with Master page, with one button on it, and We'll set
the ClientIDMode for the button control and examine what's happen when ASP.NET render
it to HTML. 
&lt;/p&gt;
&lt;h4&gt;AutoID: 
&lt;/h4&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:maroon"&gt;asp&lt;span style="color:blue"&gt;:&lt;span style="color:maroon"&gt;Button&lt;/span&gt; &lt;span style="color:red"&gt;ID&lt;span style="color:blue"&gt;="btnSubmit"&lt;/span&gt; runat&lt;span style="color:blue"&gt;="server"&lt;/span&gt; Text&lt;span style="color:blue"&gt;="Button"&lt;/span&gt; ClientIDMode&lt;span style="color:blue"&gt;="AutoID"&lt;/span&gt; &lt;span style="color:blue"&gt;/&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h5&gt;The Rendered HTML: 
&lt;/h5&gt;
&lt;p&gt;
&lt;span style="color:black; font-family:Courier New; font-size:13pt"&gt;
&lt;input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="Button" &lt;span style="background-color:yellow"&gt;id="ctl00_ContentPlaceHolder1_btnSubmit"&lt;/span&gt; /&gt;&gt; 
&lt;/p&gt;
&lt;p&gt;
It's rendered like what ASP.NET 3.5 do, so if you want to renter control's ID like
ASP.NET 3.5 set ClientIDMode to AutoID. 
&lt;/p&gt;
&lt;h4&gt;Inherit: 
&lt;/h4&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:maroon"&gt;asp&lt;span style="color:blue"&gt;:&lt;span style="color:maroon"&gt;Button&lt;/span&gt; &lt;span style="color:red"&gt;ID&lt;span style="color:blue"&gt;="btnSubmit"&lt;/span&gt; runat&lt;span style="color:blue"&gt;="server"&lt;/span&gt; Text&lt;span style="color:blue"&gt;="Button"&lt;/span&gt; ClientIDMode&lt;span style="color:blue"&gt;="Inherit"&lt;/span&gt; &lt;span style="color:blue"&gt;/&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h5&gt;The Rendered HTML: 
&lt;/h5&gt;
&lt;p&gt;
&lt;span style="color:black; font-family:Courier New; font-size:13pt"&gt;
&lt;input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="Button" &lt;span style="background-color:yellow"&gt;id="btnSubmit&lt;/span&gt;"
/&gt; &gt;
&lt;/p&gt;
&lt;p&gt;
Actually it tells the &lt;span style="color:black; font-family:Arial"&gt;control to defer
to the naming behavior mode of the parent container control&lt;/span&gt; 
&lt;/p&gt;
&lt;h4&gt;Predictable (default): 
&lt;/h4&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:maroon"&gt;asp&lt;span style="color:blue"&gt;:&lt;span style="color:maroon"&gt;Button&lt;/span&gt; &lt;span style="color:red"&gt;ID&lt;span style="color:blue"&gt;="btnSubmit"&lt;/span&gt; runat&lt;span style="color:blue"&gt;="server"&lt;/span&gt; Text&lt;span style="color:blue"&gt;="Button"&lt;/span&gt; ClientIDMode&lt;span style="color:blue"&gt;="Predictable"&lt;/span&gt; &lt;span style="color:blue"&gt;/&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h5&gt;The Rendered HTML: 
&lt;/h5&gt;
&lt;p&gt;
&lt;span style="color:black; font-family:Courier New; font-size:13pt"&gt;
&lt;input type="submit" name="ContentPlaceHolder1$btnSubmit" value="Button" &lt;span style="background-color:yellow"&gt;id="ContentPlaceHolder1_btnSubmit&lt;/span&gt;"
/&gt; &gt;
&lt;/p&gt;
&lt;p&gt;
Remove the ugly default auto generated ID prefix "ctl00" 
&lt;/p&gt;
&lt;h4&gt;Static: 
&lt;/h4&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:maroon"&gt;asp&lt;span style="color:blue"&gt;:&lt;span style="color:maroon"&gt;Button&lt;/span&gt; &lt;span style="color:red"&gt;ID&lt;span style="color:blue"&gt;="btnSubmit"&lt;/span&gt; runat&lt;span style="color:blue"&gt;="server"&lt;/span&gt; Text&lt;span style="color:blue"&gt;="Button"&lt;/span&gt; ClientIDMode&lt;span style="color:blue"&gt;="Static"&lt;/span&gt; &lt;span style="color:blue"&gt;/&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h5&gt;The Rendered HTML: 
&lt;/h5&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:13pt"&gt;
&lt;input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="Button" &lt;span style="background-color:yellow"&gt;id="btnSubmit&lt;/span&gt;"
/&gt; &gt;
&lt;/p&gt;
&lt;p&gt;
It'll rendered the ID like what you set for ID attribute 
&lt;/p&gt;
&lt;h3&gt;Where you can set the ClientIDMode: 
&lt;/h3&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h4&gt;Web.config: 
&lt;/h4&gt;
&lt;p&gt;
You can set the ClientIDMode in web.config file inside page tag 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:#a31515"&gt;configuration&lt;span style="color:blue"&gt;&gt;&lt;/span&gt; &lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:#a31515"&gt; system.web&lt;span style="color:blue"&gt;&gt;&lt;/span&gt; &lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:#a31515"&gt; pages&lt;span style="color:blue"&gt; &lt;span style="color:red"&gt;&lt;span style="background-color:yellow"&gt;ClientIDMode&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;Static&lt;/span&gt;"&lt;/span&gt;&lt;span style="color:blue"&gt; /&gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:#a31515"&gt; compilation&lt;span style="color:blue"&gt; &lt;span style="color:red"&gt;debug&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;true&lt;/span&gt;"&lt;span style="color:blue"&gt; &lt;span style="color:red"&gt;targetFramework&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;4.0&lt;/span&gt;"&lt;span style="color:blue"&gt; /&gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;span style="color:#a31515"&gt; system.web&lt;span style="color:blue"&gt;&gt;&lt;/span&gt; &lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;span style="color:#a31515"&gt;configuration&lt;span style="color:blue"&gt;&gt;&lt;/span&gt; &lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h4&gt;Control: 
&lt;/h4&gt;
&lt;p&gt;
Or you can set it for specific control, but remember the main control is inherit this
property, and this what we do in the demo. 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:blue; font-family:Consolas; font-size:12pt"&gt;&lt;&lt;span style="color:maroon"&gt;asp&lt;span style="color:blue"&gt;:&lt;span style="color:maroon"&gt;Button&lt;/span&gt; &lt;span style="color:red"&gt;ID&lt;span style="color:blue"&gt;="btnSubmit"&lt;/span&gt; runat&lt;span style="color:blue"&gt;="server"&lt;/span&gt; Text&lt;span style="color:blue"&gt;="Button"&lt;/span&gt; &lt;span style="background-color:yellow"&gt;ClientIDMode&lt;span style="color:blue"&gt;="Static"&lt;/span&gt;&lt;/span&gt; &lt;span style="color:blue"&gt;/&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h4&gt;Page: 
&lt;/h4&gt;
&lt;p&gt;
Or you can set the ClientIDMode on the page tag in the upper of ASPX file. 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Consolas; font-size:12pt"&gt;&lt;span style="background-color:yellow"&gt;&lt;%&lt;/span&gt;&lt;span style="color:blue"&gt;@&lt;/span&gt;
			&lt;span style="color:maroon"&gt;Page&lt;/span&gt;
			&lt;span style="color:red"&gt;Title&lt;span style="color:blue"&gt;=""&lt;/span&gt; Language&lt;span style="color:blue"&gt;="C#"&lt;/span&gt; MasterPageFile&lt;span style="color:blue"&gt;="~/Site.Master"&lt;/span&gt; AutoEventWireup&lt;span style="color:blue"&gt;="true"&lt;/span&gt; CodeBehind&lt;span style="color:blue"&gt;="Demo.aspx.cs"&lt;/span&gt; Inherits&lt;span style="color:blue"&gt;="ClientIDModeDemo.Demo"&lt;/span&gt;
				&lt;span style="background-color:yellow"&gt;ClientIDMode&lt;span style="color:blue"&gt;="Static&lt;/span&gt;&lt;/span&gt;"&lt;/span&gt;
			&lt;span style="background-color:yellow"&gt;%&gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt; &lt;/strong&gt; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.emadmokhtar.com/aggbug.ashx?id=a17dc236-97f0-4bc3-b39b-2c4ad8284a8b" /&gt;
&lt;br /&gt;
&lt;hr /&gt;© Copyright, Emad Mokhtar</description>
      <comments>http://www.emadmokhtar.com/CommentView,guid,a17dc236-97f0-4bc3-b39b-2c4ad8284a8b.aspx</comments>
      <category>.Net</category>
      <category>ASP.NET</category>
    </item>
  </channel>
</rss>