How can I get the length of text entered in a textbox using jQuery?$("#myTextbox").val().length; will give the length of text inmyTextbox.
Tuesday, 16 March 2010
jQuery string length
Monday, 15 March 2010
Creating an array of objects in C#
Creating an array of objects, rather than an array of simple data types such as integers, is a two-part process. First you declare the array, and then you must create the objects that are stored in the array. This example creates a class that defines an audio CD. It then creates an array that stores 20 audio CDs.
namespace CDCollection
{
// Define a CD type.
class CD
{
private string album;
private string artist;
private int rating;
public string Album
{
get {return album;}
set {album = value;}
}
public string Artist
{
get {return artist;}
set {artist = value;}
}
public int Rating
{
get {return rating;}
set {rating = value;}
}
}
class Program
{
static void Main(string[] args)
{
// Create the array to store the CDs.
CD[] cdLibrary = new CD[20];
// Populate the CD library with CD objects.
for (int i=0; i<20; i++)
{
cdLibrary[i] = new CD();
}
// Assign details to the first album.
cdLibrary[0].Album = "Must See";
cdLibrary[0].Artist = "Anonymous";
cdLibrary[0].Rating = 5;
}
}
}
Collections
An array is just one of many options for storing sets of data by using C#. The option that you select depends on several factors, such as how you intend to manipulate or access the items. For example, a list is generally faster than an array if you must insert items at the beginning or in the middle of the collection. Other types of collection classes include map, tree, and stack; each one has its own advantages. For more information, see System.Collections, and System.Collections.Generic.
The following example shows how to use the List<(Of <(T>)>) class. Notice that unlike the Array class, items can be inserted into the middle of the list. This example restricts the items in the list so that they must be strings.
public class TestCollections
{
public static void TestList()
{
System.Collections.Generic.List
sandwich.Add("A");
sandwich.Add("B");
sandwich.Insert(1, "C");
foreach (string ingredient in sandwich)
{
System.Console.WriteLine(ingredient);
}
}
}
// Output:
// A
// B
// C
How to Bind Enum Types to a dropdown list or any other bindable Control in ASP.NET?
{
RED,
GREEN,
BLUE
}
Every Enum type derives from System.Enum. There are two static methods that help bind data to a drop-down list control (and retrieve the value). These are Enum.GetNames and Enum.Parse. Using GetNames, you are able to bind to your drop-down list control as follows:
protected System.Web.UI.WebControls.DropDownList ddColor;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
ddColor.DataSource = Enum.GetNames(typeof(Color));
ddColor.DataBind();
}
}
Now if you want the Enum value Back on Selection ...
private void ddColor_SelectedIndexChanged(object sender, System.EventArgs e)
{
Color selectedColor = (Color)Enum.Parse(ddColor.SelectedValue);
}
Friday, 12 March 2010
Accessing checkbox state using jQuery
Example:
$("#checkboxid").attr("checked")
returns true or false
Also
$("#checkboxid").attr("checked", true)
sets the state of the checkbox to selected
Initializing Multi-dimensional array in Javascript
// Arrays within arrays:
var x = new Array(new Array(1,2,3),new Array('A','B','C'),new Array('x','y','z'));
alert(x[1][2]); // returns 'C'
Thursday, 11 March 2010
jQuery fadeIn/fadeOut IE cleartype glitch
The most common way to solve this problem is by removing the filter CSS attribute. In normal javascript, it would look like this:
document.getElementById('node').style.removeAttribute('filter');
and in jQuery, it would look like this:
$('#node').fadeOut('slow', function() {
this.style.removeAttribute('filter');
});
This means that every single time we want to fade an element, we need to remove the filter attribute, which makes our code look messy.
Google AdWords Conversion Tracking(PPC Tracking) : How it works?
Once you've defined an action, Google gives you a JavaScript snippet to paste on the pages you wish to track. This code builds a URL that passes parameters back to Google and also allows you to display the Google Site Stats text on your page if you opted in to show it on your conversion pages. The query string data within the JavaScript code snippet is used in the following way:
* google_conversion_id: A unique value that allows Google to identify the advertiser receiving the conversion.
* google_conversion_value: A numeric value defined by the advertiser equaling the value of the conversion.
* google_conversion_label: The type of conversion that occurred (purchase, sign-up, page view, or lead). Google does not currently support advertiser-defined conversion types. Consequently, you cannot customize this string.
* google_conversion_language: The language of the conversion tracking Google Site Stats text that appears on your website.
If you can see the code generated for your action, you can learn how to paste it into the pages you're tracking by reading our AdWords Conversion Tracking Setup Guide. Proper installation of the code on to your site activates conversion tracking. Here's how it should behave once it starts working:
1. A user clicks your AdWords ad.
2. Our googleadservices.com server places a temporary cookie on the user's computer or mobile device.
3. If the user reaches one of your designated conversion confirmation request pages, his or her computer or mobile device passes back the cookie and requests that our server send the conversion tracking text. If cookies are rejected for any reason, the conversions made from that user won't get recorded. Conversion tracking is also not supported if the mobile phone user disables images.
4. Google records the conversion event and correlates it with your campaign, ad group, URL and keyword.
5. At the next report update, you will see conversion statistics from the campaign level down to the keyword level.
How does Google use cookies in conversion tracking?
The cookie that Google adds to a user's computer when he/she clicks on an ad expires in 30 days. This measure, and the fact that Google uses separate servers for conversion tracking and search results, protects the user's privacy.
Users who don't wish to participate in tracking activities can easily not accept this cookie by setting their Internet browser user preferences. These users will simply not be included in your conversion tracking statistics.
After having activated Analytics within my AdWords account, my ads are linking to an Error page.
When Analytics is activated within AdWords, "Destination URL auto-tagging" is automatically turned on. This feature allows Analytics to track information about clicks on your AdWords ads by tagging your AdWords keyword Destination URLs with a "gclid=" parameter. This parameter is displayed in your landing page URL. For example, http://www.example.co.uk/?gclid=12345abcd
A small number of websites do not allow URL parameters and serve an error 404 page. If your site does not allow parameters, you can prevent this error from occurring by either turning "Auto-tagging" off in your account (see steps below) or asking your webmaster to allow URL parameters. You can also turn auto-tagging off if you do not want the "gclid=" parameter to appear in your URLs.
TURN AUTO-TAGGING OFF
1. Log in to your AdWords account
2. Navigate to My Account-->User Preferences
3. On this page under the Analytics section, click "Edit"
4. Turn Destination URL auto-tagging: "off"
5. Save changes