Tuesday, July 31, 2012

Check if a Function Exists in Javascript

There are times when we want to call a JavaScript function, and in certain circumstances, we want to make sure that the function does exist. e.g. When a dialog window can be opened from more than one page. And, we want to refresh the component of the the parent page from the dialog window. Thus, we need to check if the function really exists.

This is a simple yet useful example to check if a function exists in JavaScript.

<input type="button" onclick="checkFunctionExist();" value="Check Function Existence" />

<script type="text/javascript" language="javascript">

 function testFunction() {


 function checkFunctionExist() {
  if (window.testFunction) alert('testFunction exists');
  else alert('testFunction does not exist');

  if (window.nonExistantFunction) alert('nonExistantFunction exists');
  else alert('nonExistantFunction does not exist');


To check whether a function exists on the parent page (the page which opened the dialog window), use:

if(window.opener.testFunction) alert('testFunction exists');
else alert('testFunction does not exist');


Friday, July 20, 2012

The Server Was Unable to Process The Request Due to an Internal Error

Message: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
This error usually occurs when the application uses web service or similar technologies.

The solution may vary, depending on the issue faced. One thing for sure, there is one way to make sure the exact technical error of the message.

Open the web.config or app.config file of the application, then search for serviceDebug tag, then change the includeExceptionDetailInFaults attribute to true.

<serviceDebug includeExceptionDetailInFaults="false" />

Afterwards, reproduce the error. The exact technical error message should be displayed.

Thursday, July 12, 2012

Get The First and The Last Day of The Month

Just saw a question from someone on a mailing list I join asking for how to get the transactions occurring for the last three months (in other words, three months from current date).

First, you may want to do something simple.
To get the first day and the last day of the month, we can use:

DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0),
DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0) - 1

If you play around a little bit, you can also get the first day and the last day of the previous month:

DATEADD(month, DATEDIFF(month, 0, GETDATE())-1, 0),
DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) - 1

To get the transactions for the last three months, we just need to modify the number a little bit.

DATEADD(month, DATEDIFF(month, 0, GETDATE())-2, 0),
DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0) - 1

Then, just select the transactions occurring in between these ranges.

DATEADD(month, DATEDIFF(month, 0, GETDATE())-2, 0) AND
DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0) - 1


Wednesday, July 11, 2012

Select Several Rows into One Row in SQL

In SQL Server, there are times when we want to consolidate the content of several rows into one row.

Though it is not meant for sophisticated purposes, there is actually a simple and easy way to do this.
Suppose we have a Member table containing  MemberID and Name fields.

To select the names of the members in one row, simply use the query:

DECLARE @strResult VARCHAR(5000)
SELECT @strResult = COALESCE(@strResult + ', ', '') + Name
FROM Member

SELECT MembersName = @strResult

The result will be:

We can also add some conditions to the select statement.
e.g. To generate the members with name containing 'Himura', we can simply do:

DECLARE @strResult VARCHAR(5000)
SELECT @strResult = COALESCE(@strResult + ', ', '') + Name
FROM Member
WHERE Name LIKE '%himura%'

SELECT TheHimura = @strResult

And we'll get:

That's all folks :)


Related Posts

Dual Axis not Working in Tableau

Problem : When creating chart with Dual Axis, Synchronize Axis is disabled and cannot be clicked. Cause : Tableau identified this as ...

About Me

My photo
Is an ordinary unNoticed man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing. I like English and Chinese language, and know a little about them. Hence, for me, most things can best be expressed in Chinese, some in English, and the rest in others ^^

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts



Follow by Email