Monday, December 28, 2009

'Sys' is undefined - ASP.NET 2.0 Ajax Control Toolkit

To fix this:
1. Open your web.config
2. Add this in between
<httpHandlers> </httpHandlers>
section
<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>


Reference: here

The above would work fine, however it will give the following error:
Could not load type 'Microsoft.Web.Handlers.ScriptResourceHandler'.
ScriptResource.axd


Some suggested to change the code added to the following
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>

(Change the word Microsoft to System)

But it gave me this javascript error:
Sys.ArgumentTypeException. Object of type 'Sys._Application' cannot be converted to 'Sys._Application'

In order to solve this will need to add this ScriptMode="Release" on the ScriptManager tag, like this:
<asp:ScriptManager id="ScriptManager1" runat="server" ScriptMode="Release">
</asp:ScriptManager>


Reference: here

Access is denied in Ajax Control Toolkit 1

Here's what you have to do.
Change the following in the MicrosoftAjax.js
between this line :
case Sys.Browser.InternetExplorer:
and this line :
case Sys.Browser.Safari:

The code to be used:
Sys.UI.DomElement.getLocation = function Sys$UI$DomElement$getLocation(element) {
if(element.self||element.nodeType===9)
return new Sys.UI.Point(0,0);
var d = element.getClientRects();
if(!d || !d.length)
return new Sys.UI.Point(0,0);

var inFrame = false;
// Get the first bounding rectangle in screen coordinates
var screenRects = element.getClientRects();

if (!screenRects || !screenRects.length) {
return new Sys.UI.Point(0,0);
}

var first = screenRects[0];
// Delta between client coords and screen coords
var dLeft = 0;
var dTop = 0;

try
{
inFrame = a.ownerDocument.parentWindow.frameElement;
}
catch(ex)
{
inFrame = true;
}

if(!inFrame)
{
var e=a.ownerDocument.parentWindow;
var g=e.screenLeft - top.screenLeft - top.document.documentElement.scrollLeft + 2;
var h=e.screenTop - top.screenTop - top.document.documentElement.scrollTop + 2;
var c=e.frameElement||null;
if(c)
{
var b=c.currentStyle;
g+=(c.frameBorder||1) * 2 + (parseInt(b.paddingLeft) || 0) + (parseInt(b.borderLeftWidth) || 0) - a.ownerDocument.documentElement.scrollLeft;
h+=(c.frameBorder||1) * 2 + (parseInt(b.paddingTop) || 0) + (parseInt(b.borderTopWidth) || 0) - a.ownerDocument.documentElement.scrollTop;
}
var f=d[0];
return new Sys.UI.Point(f.left-g,f.top-h);
}
else
{
// Get the bounding rectangle in client coords
var clientRect = element.getBoundingClientRect();
if (!clientRect)
{
return new Sys.UI.Point(0,0);
}
// Find the minima in screen coords
var minLeft = first.left;
var minTop = first.top;

for (var i = 1; i < screenRects.length; i++)
{
var r = screenRects[i];
if (r.left < minLeft)
{
minLeft = r.left;
}
if (r.top < minTop)
{
minTop = r.top;
}

}

// Compute the delta between screen and client coords
dLeft = minLeft - clientRect.left;
dTop = minTop - clientRect.top;

// Subtract 2px, the border of the viewport (It can be changed in IE6 by applying a border style to the HTML element,
// but this is not supported by ASP.NET AJAX, and it cannot be changed in IE7.), and also subtract the delta between
// screen coords and client coords

var ownerDocument = element.document.documentElement;
return new Sys.UI.Point(first.left - 2 - dLeft + ownerDocument.scrollLeft, first.top - 2 - dTop + ownerDocument.scrollTop);
}
};
break;


Reference:
here and here

Monday, December 14, 2009

Date (no time) in SQL

To get date only, u can use this:
select Convert(datetime, Convert(VARCHAR, getdate(), 101) , 101)
alternatively
select cast (floor (cast (createddate as float)) as datetime)
Reference: here
Complete reference: here

Thursday, December 10, 2009

Could not find file 'Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0'

Problem:
Encountered this error in Microsoft Visual Studio 2005 while building the web project.
Error 123 Could not find file 'Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0'.

Resolution:
Do not use project reference, but use the dll or exe reference instead.
Then try to compile again.
It should work.

Reference: here

Tuesday, December 8, 2009

extjs - ajax.net

Use ajax combined with .net
You can use AjaxPro to get the json data.
Reference: here

EXTJS Tree panel with .NET

Monday, December 7, 2009

CheckedChanged does not work!

While I was coding, it was very hard to debug as the CheckedChanged for my Checkbox event was not working.

Found out that the AutoPostBack field was set to FALSE, it is supposed to be TRUE if you want to use the CheckedChanged event.

Obtain return value from stored procedure back to code

sqlCmd.Parameters.Add(New SqlParameter("RETURN_VALUE",SqlDbType.Int)).Direction = ParameterDirection.ReturnValue

Dim i as integer = CType(sqlCmd.Parameters("RETURN_VALUE").Value, Integer)


Reference: here

Friday, December 4, 2009

Thursday, December 3, 2009

Add blank item at the top of dropdownlist

drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty));
drpList.SelectedIndex = 0;


Reference: here

Insert Record into Database via Dataset

Click here

VB.NET Class

If the class inherit another class, you may use the baseclass sub new as follows:
Class ChildClass
Inherits BaseClass
Public Sub New(text As String)
MyBase.New(text)
End Sub
End Class


Reference: Here

More inheritance lessons

Microsoft Enterprise Library Exception Logging error

Did you encounter this error?
The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.

Simply add Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll as the reference to your project.

Reference: here

Tuesday, December 1, 2009

Remove Identity column in a table

Reset Identity in MS SQL

Remove the IDENTITY Property from an Existing Column in SQL Server 2000

Removing IDENTITY from existing column

Subquery sample

create table T3 (a int unique clustered, b int)

insert T1 values(0, 0, 0)
insert T1 values(1, 1, 1)

select
case
when T1.a > 0 then
(select T3.b from T3 where T3.a = T1.b)
else
T1.c
end
from T1


Reference: here