Author: Rizwan Ansari

SQL Snippets

Author: | Categories: Database, Programming No Comments
Rounding off to 2 decimal places cast(round([value],2) as decimal(18,2)) Compare only Year from datetime field select * from [table_name] where year(date_time_field) = year(getdate()) check if a SQL server string is null or empty ISNULL(NULLIF(text, ''), '') AS Offer_Text The differences between LEN and DATALENGTH in SQL Server LEN Returns the number of characters, rather than […]

JQuery snippets

Author: | Categories: Programming No Comments
Adding text to a span using jquery $("#spanid").text("Your text here"); Adding html to a span using jquery $("#spanid").text("HTML here"); Append html to a span using jquery $("#spanid").append("HTML here"); Check/uncheck a checkbox input or radio button $("#x").prop("checked", true); $("#x").prop("checked", false); Check checkbox checked property $("#x").is(':checked') Handle change of checkbox $('#x').change(function() { if($(this).is(":checked")) { //'checked' event code […]

Javascript console messages

Author: | Categories: Programming No Comments
Most modern browsers include Developer tools which helps developers analyze client html and scripts. To write something from Javascript to console below options are available. Error gives you the red error message console.error(message); Default gives the default message console.log(message); Warning gives the warning message with the exclamation mark in front of it console.warn(message); Information gives […]

ASP.NET Send Canvas to Server as File Using Ajax

Author: | Categories: Programming No Comments
HTML 5 introduces canvas element as a resolution-dependent bitmap canvas which can be used for rendering graphs, game graphics, or other visual images on the fly. A canvas is a rectangle in your page where you can use JavaScript to draw anything you want. Below is the code save graphics drawn on Canvas to server […]

ASP.Net persist readonly textbox value on postback

Author: | Categories: Programming No Comments
As a security measure in the the readonly fields and disabled fields loose their values in postbacks. To retain the readonly textbox value after postback instead of making the textbox readonly using properties option, use attributes in code: TextBox1.Attributes.Add(“readonly”, “readonly”); that will still make the textbox readonly and will also retain the value after […]

ASP.NET calling Webmethod using jQuery

Author: | Categories: Programming No Comments
To call Webmethod asynchronously in through jQuery Javascript Code <script type=”text/javascript”> function Authenticate() { $.ajax({ type: "POST", url: "/login.aspx/Authenticate", data: "{ provide json data }", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { if (msg.d == '1') { alert(‘authenticated’); } else { alert("not authenticated"); } }, error: function() { alert("Error :("); } }); }; […]

Enable Pretty Permalinks on WordPress

Author: | Categories: Linux, Programming No Comments
Set pretty permalinks in Settings .htaccess file must look like this # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress Enable mod_rewrite on terminal window a2enmod rewrite Enable AllowOverride in Apache config file so that Apache reads .htaccess file <Directory […]

Accessing MySQL databases from remote computer

Author: | Categories: Database, Linux No Comments
To expose MySQL other than localhost uncomment following line in /etc/mysql/my.cnf and assign to your computers IP address and not loopback bind-address = # replace xxx with IP Next for a remote user to connect with the correct privileges you need to have that user created in both the localhost and '%' as in. […]

SQL Joins

Author: | Categories: Database No Comments
Comprehensive image to show how SQL joins work

Check / Uncheck checkbox and radio button with jquery

Author: | Categories: Programming No Comments
You can check or uncheck a checkbox element or a radio button using the .prop() method // Check #x $( "#x" ).prop( "checked", true ); // Uncheck #x $( "#x" ).prop( "checked", false );