{"id":38,"date":"2011-11-08T09:24:00","date_gmt":"2011-11-08T09:24:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2011\/11\/08\/implementing-custom-classes-for-microsoft-ajax-library-part-1\/"},"modified":"2011-11-08T09:24:00","modified_gmt":"2011-11-08T09:24:00","slug":"implementing-custom-classes-for-microsoft-ajax-library-part-1","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2011\/11\/08\/implementing-custom-classes-for-microsoft-ajax-library-part-1\/","title":{"rendered":"Implementing Custom Classes for Microsoft AJAX Library (Part 1)"},"content":{"rendered":"<p>This article explainis the basic steps for impplementing your own javascript class and use it in a page.<br \/>First, you need to write a script that describes the class. This example simply provides a class that verifies the length of a word to see if it has enough length to be used as a password. The file name is PasswordStrengthComponent.js<\/p>\n<p><span style=\"font-family: 'Courier New';\">\/* When working with JavaScript files in the code editor, you can add a reference to the&nbsp;Microsoft AJAX Library. This will ensure that your coding includes IntelliSense for&nbsp;the library. This is similar to the using statement in C# and the Imports statement in&nbsp;Visual Basic. You embed this reference in a comment at the top of your .js file. The&nbsp;following shows an example.<br \/>*\/<br \/>\/\/\/ &lt;reference name=&#8221;MicrosoftAjax.js&#8221;&gt;&lt;\/reference&gt;<\/span><br \/><span style=\"font-family: 'Courier New';\">\/\/ register your namespace<br \/>Type.<strong>registerNamespace<\/strong>(&#8220;Panahy.Ajax&#8221;);<\/span><br \/><span style=\"font-family: 'Courier New';\">\/\/create constructor<br \/>Panahy.Ajax.PasswordStrengthComponent = function () {<br \/>&nbsp;&nbsp;&nbsp; Panahy.Ajax.PasswordStrengthComponent.<strong>initializeBase<\/strong>(this);<br \/>}<\/span><br \/><span style=\"font-family: 'Courier New';\">\/\/define class<br \/>Panahy.Ajax.PasswordStrengthComponent.<strong>prototype<\/strong> = {<br \/>&nbsp;&nbsp;&nbsp; <strong>initialize<\/strong>: function () {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/add custom initialization here<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Panahy.Ajax.PasswordStrengthComponent.callBaseMethod(this, &#8216;initialize&#8217;);<br \/>&nbsp;&nbsp;&nbsp; },<\/span><br \/><span style=\"font-family: 'Courier New';\">&nbsp;&nbsp;&nbsp; passwordStrengthClass: function (password) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var strPass = new String(password.toString());<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (strPass.length &amp;lt; 5) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &#8220;Weak&#8221;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (strPass.length &amp;lt; 8) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &#8220;Medium&#8221;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &#8220;Strong&#8221;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; },<\/span><br \/><span style=\"font-family: 'Courier New';\">&nbsp;&nbsp;&nbsp; <strong>dispose<\/strong>: function () {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/add custom dispose actions here<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Panahy.Ajax.PasswordStrengthComponent.callBaseMethod(this, &#8216;dispose&#8217;);<br \/>&nbsp;&nbsp;&nbsp; }<br \/>}<\/span><br \/><span style=\"font-family: 'Courier New';\">\/\/register class as a Sys.Component<br \/>Panahy.Ajax.PasswordStrengthComponent.<strong>registerClass<\/strong>(<br \/>&nbsp;&nbsp;&nbsp; &#8216;Panahy.Ajax.PasswordStrengthComponent&#8217;, Sys.Component);<\/span><br \/><span style=\"font-family: 'Courier New';\">\/\/notify script loaded<br \/>if (typeof (Sys) !== &#8216;undefined&#8217;) Sys.Application.notifyScriptLoaded();<\/span><br \/>Next, you reference this script file in your page within the ScriptManager:<\/p>\n<p><span style=\"font-family: 'Courier New';\">&lt;asp:ScriptManager ID=&#8221;ScriptManager1&#8243; runat=&#8221;server&#8221;&gt;<br \/>&nbsp;&nbsp;&nbsp; &lt;Scripts&gt;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:ScriptReference Path=&#8221;Scripts\/<strong>PasswordStrengthComponent.js<\/strong>&#8221; \/&gt;<br \/>&nbsp;&nbsp;&nbsp; &lt;\/Scripts&gt;<br \/>&lt;\/asp:ScriptManager&gt;<br \/><\/span><br \/>From this point the script is available and can be used in thepage as in the following example:<br \/><span style=\"font-family: 'Courier New';\">&lt;script language=&#8221;javascript&#8221; type=&#8221;text\/javascript&#8221;&gt;<\/span><br \/><span style=\"font-family: 'Courier New';\">&nbsp;&nbsp;&nbsp; function _<strong>OnKeypress<\/strong>() {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var checker = new Panahy.Ajax.PasswordStrengthComponent();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var pass = document.getElementById(&#8220;MainContent_TextBoxPassword&#8221;).value;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var strength = checker.passwordStrengthClass(pass);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById(<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;MainContent_TextBoxPassword&#8221;).setAttribute(&#8220;class&#8221;, strength);<br \/>&nbsp;&nbsp;&nbsp; }<br \/><\/span><span style=\"font-family: 'Courier New';\">&lt;\/script&gt;<\/span><br \/><span style=\"font-family: 'Courier New';\">&lt;asp:TextBox ID=&#8221;TextBoxPassword&#8221; runat=&#8221;server&#8221; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextMode=&#8221;Password&#8221; Width=&#8221;200&#8243; onkeyup=&#8221;_<strong>OnKeypress<\/strong>()&#8221; CssClass=&#8221;Empty&#8221;&gt;&lt;\/asp:TextBox&gt;<\/span><br \/><span style=\"font-family: 'Courier New';\"><br \/><\/span><br \/><span style=\"font-family: 'Courier New';\"><a href=\"http:\/\/wdevs.blogspot.com\/2011\/11\/implementing-custom-classes-for_08.html\">Next part<\/a> will take this subject one step forward.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article explainis the basic steps for impplementing your own javascript class and use it in a page.First, you need to write a script that describes the class. This example simply provides a class that verifies the length of a word to see if it has enough length to be used as a password. The &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2011\/11\/08\/implementing-custom-classes-for-microsoft-ajax-library-part-1\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Implementing Custom Classes for Microsoft AJAX Library (Part 1)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,31,18],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":0,"uagb_excerpt":"This article explainis the basic steps for impplementing your own javascript class and use it in a page.First, you need to write a script that describes the class. This example simply provides a class that verifies the length of a word to see if it has enough length to be used as a password. The&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/38"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=38"}],"version-history":[{"count":0,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}