{"id":241,"date":"2010-09-08T22:43:43","date_gmt":"2010-09-08T12:43:43","guid":{"rendered":"http:\/\/jcrawfor74.wordpress.com\/?p=241"},"modified":"2010-09-08T22:43:43","modified_gmt":"2010-09-08T12:43:43","slug":"jquery-enable-disable-readonly-and-how-to-reference-net-server-side-controls","status":"publish","type":"post","link":"https:\/\/ntsblog.homedev.com.au\/index.php\/2010\/09\/08\/jquery-enable-disable-readonly-and-how-to-reference-net-server-side-controls\/","title":{"rendered":"jQuery &#8211; enable \/ disable (readonly) and how to reference .Net Server side Controls"},"content":{"rendered":"<div id=\"ntsbl-2427436429\" class=\"ntsbl-before-content ntsbl-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6288941070289539\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:728px;height:90px;\" \ndata-ad-client=\"ca-pub-6288941070289539\" \ndata-ad-slot=\"9356781486\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div><p>Ok, I am just starting to play around with jQuery and these are a couple of tips that I have found useful.<\/p>\n<p><strong>1. How to access .net server side controls<\/strong><br \/>\nThe code to get the value from a html input control &lt;input id=&#8221;name&#8221;&gt;  might be  as follow:<br \/>\nvar name =  $(&#8216;#name&#8217;).val();<\/p>\n<p>For a server side control like  &lt;asp:TextBox ID=&#8221;txtName&#8221; runAt=&#8221;sever&#8221; \/&gt; you can reference it as follows:<br \/>\nvar name = $(&#8216;#&lt;%=txtName.ClientID%&gt;&#8217;).val();<\/p>\n<p>I have a user control for date selection called the DateSelector, and it has a control inside it called txtDate which stores the selected date.<br \/>\nIf I want to get the value from within a user control like this I can do:<\/p>\n<p>var dte = $(&#8216;#&lt;%=dteDateSelector.ClientID%&gt;_txtDate&#8217;).val();<\/p>\n<p><strong>2. Disable a control<\/strong><br \/>\nIn this case I want to disable a text box from the txtName example above:<br \/>\n$(&#8216;#&lt;%=txtName.ClientID%&gt;&#8217;).attr(&#8220;disabled&#8221;, true);<br \/>\nto clear it<br \/>\n$(&#8216;#&lt;%=txtName.ClientID%&gt;&#8217;).removeAttr(&#8220;disabled&#8221;)<\/p>\n<p>A problem with disabling controls in this way is that their values cannot be read in javascript, so another way is to use the &#8220;ReadOnly&#8221; attribute<br \/>\n$(&#8216;#&lt;%=txtName.ClientID%&gt;&#8217;).attr(&#8220;readonly&#8221;, true);<br \/>\nto clear it<br \/>\n$(&#8216;#&lt;%=txtName.ClientID%&gt;&#8217;).removeAttr(&#8220;readonly&#8221;)<\/p>\n<p>Cheers<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok, I am just starting to play around with jQuery and these are a couple of tips that I have found useful. 1. How to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,9],"tags":[],"class_list":["post-241","post","type-post","status-publish","format-standard","hentry","category-asp-net","category-jquery"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":0,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"wp:attachment":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}