Quote of the day

Friday, December 24, 2010

jQuery method in common javascript file for asp.net

Today, I faced an issue with "object required" error in javascript in my aspx pages. I'm working on the enhancement part of my project. As I'm curious of using jQuery, I implemented it in the page which I developed. Since there was only one javascript common file written for the whole project, I created events for buttons and other controls in that file.
I inherited common javascript file in my page and everything was working fine. But in other pages it was throwing "object required" error which is not suppose to happen. When I debugged the application, I got error in the jQuery events which I created.
The reason is, when other pages are loaded, jQuery script is trying to register the events which I've written for the new page I created. I, then used try.. catch.. inside the event, but still error persisted. Then my slow brain recognized that the event registration is causing the error. So I used try.. catch.. for registering events itself. Cool, my problem solved then.
Below did the trick:
try {
$("#btnSample").live("click", function() {
//do something
});
}
catch (err) {
}
Since try.. catch.. is used, even if it throws error, it would be catched and the error won't display!

Alternatively, you can use window.onerror method to return true whenever an error occurs is any of the method in javascript, which is actually not recommended.

Friday, December 17, 2010

Free EBooks - legal

Now you can find most of the ebooks for free. Check the below link:

http://www.onlinecomputerbooks.com/

Wednesday, December 15, 2010

Exporting DataSet to Excel in asp.net problem




Last night I had an issue with exporting the asp.net dataset/datatable to excel. Requirement is to export the data into an Microsoft excel sheet. There are about 13 columns and few columns have to be in specific format. The problem was with formatting.
Couple of columns have to be in dd/MM/yyyy 00:00:00 format, so for example when the date is June 08, 2010, then the date should look like 08/06/2010 00:00:00. But for me it was displaying like 8/6/2010 which is not suppose to be. I googled for almost 2 hours for the solution, but nothing worked. Finally today I got an idea to use the formatting option available in excel sheet. When the data is passed from c# code, it can be concatenated with default excel function available.


I need to use the TEXT function in excel sheet so that it displays exactly what I send. I found the formatting options here http://www.techonthenet.com/excel/formulas/text.php

Used the following code for formatting the date as text:


Similarly, we can use the above code for formatting decimal numbers as well. Check the given link for decimal conversion as well.

Use the below code for decimal conversion. Eg: 123.44, 880.08, 334.30, 0.00







Monday, December 13, 2010

The EXECUTE permission was denied on the object 'storedProcedureName', database 'databaseName'

Today we deployed an updated version of our web application for my module. In the new module, I created a stored procedure which pull records based on the dates passed. It executed perfectly in my local machine, but when I deployed in our development/testing server, I got the following error:
The EXECUTE permission was denied on the object 'storedProcedureName', database 'databaseName'
We thought that the network\user (active directory user) doesn't have rights to execute the SP, so I contacted the DB team to give rights and it was given. But still I was getting the same error.
Later my onsite coordinator said that we are using service id in our application and that service id should be given rights/access to execute the Stored Procedure.
Service ID would be something like network\svc.yourServiceID
network - your active directory server

Access was given and we were able to execute the stored procedure!!

Wednesday, December 08, 2010

a connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed....

Hi,
Yesterday we had a problem calling 3rd party webserivce where we received the following error:
a connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond (my external IP address):(port)

I created a web proxy for Secured SSL in c#, but still was not able to establish the connection.

Earlier I created a sample console application which calls the webservice with the same code used in the original application. That console application was able to call the 3rd party webservice and got the result too! We almost wasted a day reasearching for this, though we knew there is some problem with the application configuration. No clue which configuration it was?
Actually, our application executes as tasks (like jobs in sql server) every 15 mins. There was the problem. We had to configure the tasks which permitted the application to call the 3rd party webservice. It worked then!!!

Wednesday, December 01, 2010

Maintain Scroll Position after Asynchronous Postback

Below code is used to maintain the scroll for grid or any other controls when it is posted back.