Alex B. Clarke

Hi, I am a software developer specialising in Microsoft .Net technologies. This site is used to interact with, and contribute to development community.

Send mail to the author(s)  Contact me
Feed your aggregator (RSS 2.0)  Syndicate
On this page....
Categories
Archives
Blogroll
Blog Stats
Total Posts: 43
This Year: 5
This Month: 0
This Week: 0
Comments: 33
Misc
Theme by Alex B. Clarke.

Copyright © 2010 Alex B. Clarke. All rights reserved.

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

# Saturday, February 28, 2009

Validate Asp.Net Page from JavaScript
Call Page_ClientValidate(), it returns TRUE if validators are happy, false if not. Use it on client side to prevent javascript code from executing if ASP.Net validators ring alarm bells.
http://www.codeproject.com/KB/aspnet/JavascriptValidation.aspx

Firefox and onChange event
First of all it is fired before keyUp or keyDown
Secondly it's fired again when cursor leaves text area

Firefox and Attributes.Add() Method
In IE to retrieve a custom attribute added in Asp.Net using Control.Attributes.Add() method, you call element.AttributeName or element['AttributeName'].
In Fire Fox we have to use
element.attributes['attributeName'].value or
element.attributes.attributeName.value

Firefox Css Class Name for Disabled Elements
You can use this class in your css file to alter the disabled elements appearance
input[disabled], textarea[disabled], option[disabled], optgroup[disabled], select[disabled]
{
  -moz-user-focus:ignore;
  -moz-user-input:disabled;
  background-color:threedface;
  color:graytext;
  cursor:inherit;
}

"This page displays secure and unsecure  content ..." Warning in IE over SSL
This can happen if, as in my case, there are relative paths to resources in client script and your site is configured to use SSL. To solve this problem either use absolute path starting with "https://" or move the paths to css. Neither FF no Safari care about it.

Cell Border Does Not Show When Cell Is Empty - IE Bug Fix
Apply the following style to the table
style="empty-cells:show; border-collapse:collapse;"

How to get Text Value from Microsoft AutoCompleteExtender
1. In the web method use the following method to create strings that will be returned in the array
AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(textToShow, valueForTheText );
2. In the AutoCompleteExtender assign event handler
OnClientItemSelected="EventHadlerClientSideMethodName"
3. In the event handler use the following method signature
EventHadlerClientSideMethodName(source, eventArgs)
4. Get text and value
eventArgs._text
eventArgs._value

IE8 will throw an error "Unterminated string constant" 
windows.setTimeOut method in IE8 will throw an error "Unterminated string constant" if newLine 
carrigeReturn is present. Hence we explicitly replace them with terminating \n\r 
IE7, FF and Opera are all fine

Example - cleaning currentTaskText
var re = /\n/g;
currentTaskText = currentTaskText.replace(re, '\\n');
re = /\r/g;
currentTaskText = currentTaskText.replace(re, '\\r');

jQuery Intellisense in Visual Studio 2008
1. Download the latest "jquery-1.3.2-vsdoc.js"
2. Place it in a folder in your project. It does not matter if the project type is "Web Site" or "Web Application"
3. Open your javascript file, the one where you want jQuery intellisense enabled, in VS2008
4. Drag "jquery-1.3.2-vsdoc.js" file and drop it in VS Editor Window. This will add a line of code similar to this one
/// <reference path="../jQuery/js/jquery-1.3.2-vsdoc.js" />

IMPORTANT
The reference must be the very first line in the file. I had a comment before it and the intellisense did not work and this kept me busy for a while, googling etc, with no results, until I just thought about it.

Just found this great post about referencing other files in javascript files in VS2008
JScript IntelliSense: A Reference for the “Reference” Tag
It covers all possibilities of referencing.  

Storing JSON Object in an Elemet's Attribute
Writing JSON object to a newly-created attribute at the time the attribute is created will not work.
So this code is not going to write JSON object correctly, instead it will write a string '[Object]'
var myJsonObj = GetMyJsonObject();
$('#' + elemetId).attr('jsonObject', myJsonObj);
Here's how you should do it
1. Create an attribute and explicitly declares its initial value as an object
$('#' + elemetId).attr('jsonObject', new Object);

2. Get JSON object you want to store and write it to the newly created attribute
var myJsonObj = GetMyJsonObject();
$('#' + elemetId).attr('jsonObject', myJsonObj);

Detecting Browsers Using CSS Style Sheet
http://www.sitepoint.com/forums/showthread.php?threadid=386094
<style type="text/css">
    head+/**/body{background:#ccffcc;}/*min-height browser but not IE7*/
    /* mac hide \*/
    * html body{background:#ccffff;}/* IE<7 */
    /* End hide */
    *+html body{background:#ffffcc;}/* IE>6 */
    </style>

also
<!--[if IE 6]>
Do IE stuff
<![endif]-->

plus
<!-- for IE7 only -->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/xtras/ie7only.css" media="screen" />
<![endif]-->
<!-- for IE6 only -->
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="/xtras/ie6only.css" media="screen" />
<![endif]-->
<!-- for 5 & 5.5 -->
<!--[if lt IE 6]>
<link rel="stylesheet" type="text/css" href="/xtras/old.css" media="screen" />
<![endif]-->

to hide code
<!-- for everybody else except IE 5, 5.5 and 6 -->
<!--[if !IE]>-->
<link rel="stylesheet" type="text/css" href="/xtras/new.css" media="screen" />
<!--<![endif]-->


Load JavaScripts Dynamically Using jQuery.getScript()

function button_click() {
   // Check if method is defined
   if (typeof DynFunction === "undefined") {
      // Load script file where the method is defined
      var req = LoadMyScript('proj_scripts/dyn-loaded.js');
      // Check if loaded
      if (req.status === 200) {
         // Call function from the loaded file
         DynFunction();
      }
   }
}

function LoadMyScript(scriptName) {
   // Load synchronously to ensure that the file is fully loaded
   // before being used
   $.ajaxSetup({ async: false });
   var req = $.getScript(scriptName);
   // Revert back to async loading
   $.ajaxSetup({ async: true });
   alert('status: ' + req.status + '\n\rstatusText: ' + req.statusText);
   return req;
}

 

Reference jQuery in Master Page

 <%--Referencing javascript in a master page maintaining intllisence--%>
 <%--Notice '~' sign in the script reference--%>
 <%if ( false ) { %>
    <script src="~/jQuery/js/jquery-1.3.2.min.js" type="text/javascript"></script>
 <%} %>
 <script src=<%= ResolveUrl("~/jQuery/js/jquery-1.3.2.min.js") %>  type="text/javascript"></script>
 <%--End--%>
Filed under: Client Side  | Published by: Alex B. Clarke  | Comments [0]