Add Tooltip to ListBox Control in ASP.NET

I was trying add a title or horizontal scroll bar to one of my asp.net listbox control. This is required because few of my list item text was lengthy. Finally I got solution.

foreach (ListItem item in lstSourceList.Items)
{
item.Attributes.Add(”title”, item.Text);
}

Comments (2)

Detect Enter key and click on button in Javascript

function DetectNEnter(e, btn)
{
var characterCode;
if(e && e.which) // NN4 specific code
{
    e = e;
    characterCode = e.which;
}
else
{
    e =
event
   
characterCode = e.keyCode; // IE specific code
}
if (characterCode == 13) //// Enter key is 13
{
    e.returnValue=
false;
    e.cancelBubble =
true;
    document.getElementById(btn).click();
}
    else return false;}

txtOrd.Attributes.Add(“onKeyPress”, DetectNEnter(event, ‘” + btnGo.ClientID + “‘)”);

Comments (4)

Alternate to InnerText in Javascript

We all have used control.innertext property in javascript, but we all know the problem of browsers. Today I came to know that “innertext” property is not working in firefox/safari. what now ? Use “textContent” in lieu of “innertext” property. However “innerHtml” property is working fine with all browsers. COOL :)

E.g. :

var completeText = document.getElementById(’divText’).textContent; // same as innertext.

Comments (1)

Deferred Query and Non-deferred query

A query is called to be deferred when it is performed during enumeration of the object and Non-deferred query is performed at the time when the query is called.

Example :

Lets say we have an array of integer:
int[] intArray = new int[] { 1,2,3,4,5 };

and we fire  a Linq query on that:
IEnumerable<int> ints = intArray.Select(i => i>2);

//Non-deferred query will be performed here.
// List<int> ints = intArray .Select(i => i>2).ToList();

//Print

//Deferred query will be performed here.
foreach (int item in ints)
{
   Console.WriteLine(” – ” + item + ” – “);
}

 

If by chance I change the value of 0th index of intArray, it will be reflected without again firing Linq query.

Deferred Query,  will be performed during enumeration (when calling foreach) and not when query is executed and  reverse in the case of non-deferred i.e. it will be performed when query gets executed.

Leave a Comment

Safari : Pop Up Problem.

Once upon a time,  ha ha ha. Hold it. Today itself I was working with pop up window and it was not working in Safari. Why ? Even I wondered. Everything seems to be fine, except except URL.Safari needs a http request to process a page and may be to process some JS :)

So after entering a complete URL, like http://localhost/saftest/index.htm, my pop up started running successfully.

Leave a Comment

Linq and its Components

LINQ is all about queries, whether they are queries returning a set of matching objects, a single object, or a subset of fields from an object or set of objects. In LINQ, this returned set of objects is called a sequence.

LINQ to Objects :
LINQ to Objects is the name given to the IEnumerable<T> API for the Standard Query Operators. It is LINQ to Objects that allows you to perform queries against arrays and in-memory data collections.

LINQ to XML :
LINQ to XML is the name given to the LINQ API dedicated to working with XML. This interface was previously known as XLinq in older prerelease of LINQ.

LINQ to DataSet :
LINQ to DataSet is the name given to the LINQ API for DataSets. Many developers have a lot of existing code relying on DataSets.

LINQ to SQL :
LINQ to SQL is the name given to the IQueryable<T> API that allows LINQ queries to work with Microsoft’s SQL Server database. This interface was previously known as DLinq in older prerelease of LINQ.

LINQ to Entities :
LINQ to Entities is an alternative LINQ API that is used to interface with a database. It decouples the entity object model from the physical database by injecting a logical mapping between the two.

Leave a Comment

Widening conversion and Narrowing conversion

Both Visual Basic and C# allow implicit conversion if the destination type can accommodate all possible values from the source type. That is called a widening conversion.

E.g. :

// C#
int intValue = 10;
double dblValue = 10.1001;
dblValue = intValue; // Conversion allowed.

If the range or precision of the source type exceeds that of the destination type, the operation is called a narrowing conversion, which usually requires explicit conversion.

Source : 70-536

Leave a Comment

Differences in raising events in Visual Basic and C#

Visual Basic and C# differ when raising events. In C#, you must check whether the event is null
before calling it. In Visual Basic, you can omit that check.

Leave a Comment

Get Absolute path from relative path without using tilde (~)

I hope it is not at all needed to explain how to get absolute path with tilde(~), but sometimes we may need to get absolute path without using tilde(~). Lemme tell you when, its when you pass path in a query string to some URL. At that time you wont get absolute path using tilde(~).

At that time you need to use HttpRuntime.AppDomainAppVirtualPath instead of tilde(~). Simple concat HttpRuntime.AppDomainAppVirtualPath  + path.

Simple huh !

Leave a Comment

How to load multiple silverlight elements on one page?

Hi all. Recently I have started learning and working silverlight. Here I am not explaining what it is as this you might get anywhere. Anyway’s lets consider that we know how to load silverlight element on page, but what if I want to load more then one. Here it is how.

We must be knowing that there is a respective file for its html file named TestPage.html.js in which there is a method called “createSilverlight”. I have just renamed it to “createSilverlightEx”. Now to load silverlight element it needs one xaml page, a parentid where it needs to load and one elementid which is a unique id for all loaded silverlight controls.

Besides writing method “createSilverlight” again and again to create various silverlight elements, just have 3 params in “createSilverlightEx” method. Hence it will create controls as many depends on params.

function createSilverlightEx(xamlFile, parentID, elemID)

{
    Silverlight.createObjectEx({
        source: xamlFile, // 1st PARAM
        parentElement: document.getElementById(parentID), // 2nd PARAM
        id: elemID, // 3rd PARAM
        properties: {
            width: “700″,
            height: “150″,
            version: “1.1″,
            enableHtmlAccess: “true”
        },
        events: {}
    });

}

Leave a Comment

Older Posts »