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

Thursday, July 2, 2009

Append string in front to StringBuilder

Here's how to append string in front for StringBuilder
StringBuilder sb = new StringBuilder();
sb.Append("sample");
sb.Insert(0, "firststring ");
string s = sb.ToString();

Reference: here

Tuesday, June 30, 2009

A potentially dangerous Request.Cookies value was detected from the client

A potentially dangerous Request.Cookies value was detected from the client (AppEvtStat="Deal...").

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

To resolve this:
Add validateRequest="false" on the Page element like below

<%@ Page validateRequest="false" %>

Reference: here

Monday, June 29, 2009

Firefox enable windows authentication

To enable windows authentication on your domain.

1. Open Firefox

2. Enter on url textbox: about:config

3. Locate the following preference names and put as the value the comma separated values of the address roots.

network.automatic-ntlm-auth.trusted-uris
network.negotiate-auth.delegation-uris
network.negotiate-auth.trusted-uris


Your value should look something like this: localhost, server1, server2, serverX, something.com

Reference: here

Thread was being aborted.

Error: Thread was being aborted.

Stack Trace :

at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url)

Response.Redirect is added within a try-catch block by ONLY providing a url will cause the above error.

An exception will be thrown, even though it can still redirect to the URL that you want. (you can track this error in debug mode)

To resolve this:
Response.Redirect(url,false)

add a boolean indicator to end the response

Reference: here

Monday, June 22, 2009

RUN command shortcuts

Accessibility Controls : access.cpl
Add Hardware Wizard : hdwwiz.cpl
Add/Remove Programs : appwiz.cpl
Administrative Tools : control admintools
Automatic Updates : wuaucpl.cpl
Bluetooth Transfer Wizard : fsquirt
Calculator : calc
Certificate Manager : certmgr.msc
Character Map : charmap
Check Disk Utility : chkdsk
Clipboard Viewer : clipbrd
Command Prompt : cmd
Component Services : dcomcnfg
Computer Management : compmgmt.msc
Date and Time Properties : timedate.cpl
DDE Shares : ddeshare
Device Manager : devmgmt.msc
Direct X Control Panel (If Installed)* : directx.cp
Direct X Troubleshooter : dxdiag
Disk Cleanup Utility : cleanmgr
Disk Defragment : dfrg.msc
Disk Management : diskmgmt.msc
Disk Partition Manager : diskpart
Display Properties : control desktop
Display Properties : desk.cpl
Display Properties (w/Appearance Tab Preselected) : control color
Dr. Watson System Troubleshooting Utility : drwtsn32
Driver Verifier Utility : verifier
Event Viewer : eventvwr.msc
File Signature Verification Tool : sigverif
Findfast : findfast.cpl
Folders Properties : control folders
Fonts : control fonts
Fonts Folder : fonts
Free Cell Card Game : freecell
Game Controllers : joy.cpl
Group Policy Editor (XP Prof) : gpedit.msc
Hearts Card Game : mshearts
Iexpress Wizard : iexpress
Indexing Service : ciadv.msc
Internet Properties : inetcpl.cpl
IP Configuration (Display Connection Configuration) : ipconfig /all
IP Configuration (Display DNS Cache Contents) : ipconfig /displaydns
IP Configuration (Delete DNS Cache Contents) : ipconfig /flushdns
IP Configuration (Release All Connections) : ipconfig /release
IP Configuration (Renew All Connections) : ipconfig /renew
IP Configuration (Refreshes DHCP & Re-Registers DNS) : ipconfig /registerdns
IP Configuration (Display DHCP Class ID) : ipconfig /showclassid
IP Configuration (Modifies DHCP Class ID) : ipconfig /setclassid
Java Control Panel (If Installed) : jpicpl32.cpl
Java Control Panel (If Installed) : javaws
Keyboard Properties : control keyboard
Local Security Settings : secpol.msc
Local Users and Groups : lusrmgr.msc
Logs You Out Of Windows : logoff
Microsoft Chat : winchat
Minesweeper Game : winmine
Mouse Properties : control mouse
Mouse Properties : main.cpl
Network Connections : control netconnections
Network Connections : ncpa.cpl
Network Setup Wizard : netsetup.cpl
Notepad : notepad
Nview Desktop Manager (If Installed) : nvtuicpl.cpl
Object Packager : packager
ODBC Data Source Administrator : odbccp32.cpl
On Screen Keyboard : osk
Opens AC3 Filter (If Installed) : ac3filter.cpl
Password Properties : password.cpl
Performance Monitor : perfmon.msc
Performance Monitor : perfmon
Phone and Modem Options : telephon.cpl
Power Configuration : powercfg.cpl
Printers and Faxes : control printers
Printers Folder : printers
Private Character Editor : eudcedit
Quicktime (If Installed) : QuickTime.cpl
Regional Settings : intl.cpl
Registry Editor : regedit
Registry Editor : regedit32
Remote Desktop : mstsc
Removable Storage : ntmsmgr.msc
Removable Storage Operator Requests : ntmsoprq.msc
Resultant Set of Policy (XP Prof) : rsop.msc
Scanners and Cameras : sticpl.cpl
Scheduled Tasks : control schedtasks
Security Center : wscui.cpl
Services : services.msc
Shared Folders : fsmgmt.msc
Shuts Down Windows : shutdown
Sounds and Audio : mmsys.cpl
Spider Solitare Card Game : spider
SQL Client Configuration : cliconfg
System Configuration Editor : sysedit
System Configuration Utility : msconfig
System File Checker Utility (Scan Immediately) : sfc /scannow
System File Checker Utility (Scan Once At Next Boot) : sfc /scanonce
System File Checker Utility (Scan On Every Boot) : sfc /scanboot
System File Checker Utility (Return to Default Setting) : sfc /revert
System File Checker Utility (Purge File Cache) : sfc /purgecache
System File Checker Utility (Set Cache Size to size x) : sfc /cachesize=x
System Properties : sysdm.cpl
Task Manager : taskmgr
Telnet Client : telnet
User Account Management : nusrmgr.cpl
Utility Manager : utilman
Windows Firewall : firewall.cpl
Windows Magnifier : magnify
Windows Management Infrastructure : wmimgmt.msc
Windows System Security Tool : syskey
Windows Update Launches : wupdmgr
Windows XP Tour Wizard : tourstart
Wordpad : write

taken from here

Wednesday, April 8, 2009

Find Last day of the month

To find the last day of the month in SQL:
—-Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
LastDay_PreviousMonth
—-Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
LastDay_CurrentMonth
—-Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))

Source: here

Thursday, April 2, 2009

Learn 3dMax, Adobe etc Online

Website: lynda.com

Need to pay $25 but unlimited, with video quicktime and a good teaching structure.
if you signed up with premium, practice file will be given.

Monday, March 23, 2009

Get list of all tables in SQL and its approximate row count

Here's the SQL to do this.
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER BY
2 DESC

Kewl, huh!?
Reference: here

Thursday, March 19, 2009

Bracket Plus Sign (+) in SQL

SELECT *
FROM TABLE1 a, TABLE2 b
WHERE a.CODE = b.CODE(+)


This bracket plus sign (+) indicates a LEFT OUTER JOIN. It includes all records from TABLE1 and from TABLE2 that has CODE field value match.

Click here for more information

Monday, March 16, 2009

Clear Browsing History in IE7

Create batch file (for example: New_IE.bat)

Fill the file with this:
C:\Progra~1\Intern~1\iexplore.exe
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

When we exit Internet Explorer, System will clear all the history.
This only works for IE 7.

anonymizer
nph-proxy: website that will not write the history to the proxy.
http://www.bpcd.net/cgi-bin/nph-proxy.cgi
enter URL on the site, open all sites, only that url will show in the nph-proxy

or you can use this so that won't keep the history.
chrome: incognito
ie8 (beta): sorry, forgot the name
firefox: there's an option to clear

Wednesday, March 11, 2009

Identity after inserting

How is exactly to get the identity after inserting in MS SQL?
If the table u are inserting have identity set to YES.
Hence you can use this.
declare @theid as bigint
insert into tablename select myvalue1, myvalue2
set @theid=@@IDENTITY


So the new ID is kept in the variable @theid now.

Reference: here

Tuesday, March 10, 2009

BCP function

You can use this BCP function easily to import/export from the MS SQL database.

usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"]

Here's an example to export the data from the database.
- with trusted connection
bcp "dbname.dbo.tablename" out "dev_tablename.bcp" -e error.log -c -S servername -T -k

- with username and password
bcp "dbname.dbo.tablename" out "dev_tablename.bcp" -e error.log -c -S servername -U username -P password -k


Here's an example to import the data to the database.
- with trusted connection
bcp "dbname.dbo.tablename" in "dev_tablename.bcp" -e error.log -c -S servername -T -k

- with username and password
bcp "dbname.dbo.tablename" in "dev_tablename.bcp" -e error.log -c -S servername -U username -P password -k

- with username and password and order clause
bcp "dbname.dbo.tablename" in "dev_tablename.bcp" -e error.log -c -S servername -U username -P password -k -h "ORDER (TheDate DESC)"

Monday, February 16, 2009

Select Nth Row

SQL Query:
SELECT TOP 1 name FROM (SELECT TOP 9 name FROM master..syslogins ORDER BY name ASC) sq ORDER BY name DESC -- gets 9th row

MSSQL Injection Cheat Sheet

Looping in MSSQL
declare @index integer
set @index = 0
while @index < 10
begin
select 'loop counter = ', @index
set @index = @index + 1
end

Friday, February 6, 2009

Find computer using IP

On command prompt we can type this:

NSLOOKUP

it will show the computer name.

Tuesday, February 3, 2009

Cannot delete file: cannot read from source file or disk


When we receive this kind of error what to do??
The files within this folder is somehow corrupted.
First step is to fix it.
1. Open command prompt (Start -> Run -> cmd)
2. Type chkdsk /F E:\
It will fixed by itself.

Thursday, January 8, 2009

PHP Get User Information

Class features:
* Get User Browser.
* Get User Operating System.
* Get User IP.
* Get User Country.
* Get User Referral + Search Engine.
* Get User Language.
* Check if Flash enabled.
* Check if JavaScript enabled.
* Check user speed (bandwidth).

Download the file.

Reference: here

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 134 bytes)

When you received this kind of error in PHP

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 134 bytes) in /home/www/domains/www.salzwimmer.at/html/gb/PYG.php on line 181


Here's how to resolve in xampp:
1. Enable the Rewrite module.
Open %XAMPP%\apache\conf\httpd.conf in notepad and search for mod_rewrite. You will find a line like:
#LoadModule rewrite_module modules/mod_rewrite.so

Remove the # from the beginning. It will now look:
LoadModule rewrite_module modules/mod_rewrite.so

Restart the Apache web server through XAMPP control panel.

2. Find php.ini in your folder
Change the memory_limit to 64M
Here are the files that I changed:
%XAMPP%\php\php.ini
and
%XAMPP%\apache\bin\php.ini

Find a line like:
memory_limit = 32M ; Maximum amount of memory a script may consume (16MB)

Change to
memory_limit = 64M ; Maximum amount of memory a script may consume (16MB)


Save the file and restart the Apache web server.
You should be able to resolve this error.

To check on the configuration:
1. Go to localhost/xampp
2. Click on the phpinfo()
3. Find for memory_limit
4. See if it's 64M instead of 32M