Tuesday, January 5, 2010

ASP.NET Dropdown SelectedValue does not change?

Problem:
My dropdown selected value does not change.
It will always return the initialized value.

Solution:
Check if you put the initialization within the page.ispostback criteria.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
ddl.SelectedValue = "1"
End If
End Sub

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)
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.