ASP.NET AJAX: Sys is not defined

May 20th, 2012

This becomes a real pain sometimes. Unfortunately, there is no solid way to find out what is wrong. Well, I will share my tip as well.

If you have tried everything (including checking of web.config entries), and you are still getting this error, try this.

Create an empty file at your domain root named :ScriptResource.axd
Create an empty file at your domain root named :WebResource.axd

and that might work for you.

I had this issue, checked everything is correct, all entries in web.config was good as well. Tried to change the version from .NET Framework 2.0 to 3.5 and vice versa. Nothing worked, finally I found it somewhere on the internet about these empty files and when I tried, it worked.

Phew…………..

Posted in Other | No Comments »


Redirect to Different Page if user is Authenticated but doesn’t have access to the page

January 6th, 2012

In ASP.NET, you can use Forms Authentication to redirect user to the login page, whenever he is not authenticated and requests a page. But look at the scenario where user requests a page, which should be accessible to certain roles only. For example, an admin page/folder which should be accessible to Admin role only, not a normal registered users.

  <location path="Admin">
    <system.web>
      <authorization>
        <allow roles="Administrator" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>

User is authenticated, and when tried to view above folder/page, he will be redirected back to login.aspx page as he is not authenticated for this location/page. It should be better if you redirect him to a certain page where you can write him that he need approprate permissions to visit that page. Here is the simple thing you need to do.

Add following code in Global.asax.vb

        If Response.StatusCode = 302 Then  '302 means, user doesn't have permissions for a specific page. authorization failed
            If sUserAuthenticated Then
                Response.RedirectLocation = "/noPermission.aspx?pagePath=" & Server.UrlEncode(Request.Url.PathAndQuery)
            End If
        End If

That’s simple! No?

Posted in Other | No Comments »


Select DISTINCT records from DataTable

September 8th, 2011

Often, we need to select distinct records from the DataTable, but data table doesn’t expose any such method directly. However, with DataView, we can convert that back to table with option of DISTINCT records. Here is the simple method.

Note: dt is the DataTable object.

dt.DefaultView.ToTable(True, “DistinctColumn1″, DistinctColumn2″……)

Where first parameter says if you want to select DISTINCT records or not. And rest is the list of columns to select DISTINCT based on.

I used the following line of code for having my discint result.

dt = dt.DefaultView.ToTable(True, “ProductID”, “ProductName”, “LastCost”, “AverageCost”, “InventoryAvailableQty”)

Getting back distinct results in the same datatable. The speed is really fast. Previously, I was using RemoveAt method previously to remove duplicate rows and it was taking a lot of time, but using DISTINCT, it worked very fast.

Posted in Other | No Comments »


Returning Row Number when you use SELECT

June 23rd, 2011

Sometimes, you might need to include the row number (continious values like 1,2,3,4,5………….) from your SELECT query. when I needed that, I tried to google and found nothing special but a couple of guys were trying to use some technique like sub query and a temporary table to do the job. But later I found, SQL server has built in capability of this.

You can use ROW_NUMBER() method from Transact-SQL which will require the column to sort by. Usage is like this

ROW_NUMBER() OVER (<partition BY clause> <order BY clause>)

Like

SELECT FirstName ROW_NUMBER() OVER (ORDER BY FirstName) 
   FROM CustomerTable

An example for MSDN

USE AdventureWorks;
GO
WITH OrderedOrders AS
(SELECT SalesOrderID, OrderDate,
ROW_NUMBER() OVER (ORDER BY OrderDate)AS RowNumber
FROM Sales.SalesOrderHeader ) 
SELECT * 
FROM OrderedOrders 
WHERE RowNumber BETWEEN 50 AND 60;

Posted in Other, SQL Server | 4 Comments »


I was dying to

June 22nd, 2011

Posted in Other | No Comments »


Why I Don’t Backup

June 22nd, 2011

Put simply, if catastrophe strikes and I lose all of my data, I’m okay with that.

The reasons for keeping backups are myriad, but ultimately all come back to the fact that a person simply cannot afford to lose whatever data they have accumulated. I don’t find myself in that position.

Many people keep all of their important information, including photographs, financial information and more on their computer. It exists as nothing more than bits and bytes, 1s and 0s. For myself, however, that doesn’t apply.

My insurance information, my financial records, and any other important documents all physically exist. I can hold them in my hand, I can photocopy them, and more importantly, if they are ever destroyed, I can get new copies from the relevent institutions.

The other data that exists on my computer primarily takes the form of text-files and MP3s. The text files are all either draft articles that started then promptly gave up on, or published articles. The MP3s are all easily replaceable – if they’re important enough albums, I’ll remember them; if not, then it doesn’t really matter.

I haven’t written any scripts, or customised my Mac in any meaningful way, so there is nothing to lose there.

That just about covers any and all variety of data that I have bar one: images. I don’t take photos very often, and I absolutely detest having my photo taken. As a result, all of the photos that I do have are copies of photos that Rachel has taken. And any photos that Rachel has taken that are worth saving exist on her Facebook profile. I can happily lose all the other screenshots, and saved lolcats without any pain whatsoever.

Ultimately, I looked at the data that I have on my computer, looked at the effort that implementing a worthwhile backup would take, and assessed the benefits of doing so. In my case, the effort outweighed the benefits, and I decided that I can live with the loss of my data.

Originally Posted at: http://deanacus.com/2011/06/why-i-dont-backup/

Posted in Other | 1 Comment »


Micorosft Kinect SDK (Beta) Launched

June 21st, 2011

Now is the time to bring all your movements to the Windows! Lets build something.

Download SDK here.

(Do share with me what you build :) )

Posted in Other | 1 Comment »


Happy birthday Uzair

April 20th, 2011

Wow! my kid Muhammad Uzair Javed celebrated his first birthday. Time flies man!

Let me share some pictures of him.

 

Posted in Other | No Comments »


Cricket World Cup Semi Final! Pakistan vs. India! War about to begin

March 29th, 2011

And the battel beigns!

Circket is the heart beat for both Indian and Pakistani peoples. Both are crazy for it. Now with the semi final match between Pakistan and India, made it worst!

March 30, 2011, the semi final between Pakistan and India in Mohali (India) is going to happen. Everyone in Pakistan and India is just talking for it. A ticket of 5,000 Indian Rupee is being sold in 150,000 Indian rupee. Even the worst, an Indian person is willing to sell his kideny just to get the ticket of the match. Saying, he can live with one kideny, but if he didn’t see the match in the ground, his life will be worthless.

Wow! too much craze! Everyone has forgot the “terrorism” in Pakistan and India, no channel is broadcasting any terrorism news or so, no talk show is live but with cricket being discussed. Even the govt. is now involved and its publically off in some provinces and others are closed in half day. Big screens are arranged by the govt. on public grounds to “enjoy” the match. Thousands of security personnals are assigned to playes in India to avoid any “terrorism”. Millions of dollars are placed on bets. Almost no one will be working during the match tomorrow.

Indian team captain said when they won the quarter final and qualified for the semifinal with Pakistan “Our people doesn’t want to win the world cup, but they want us to have a must win form Pakistan”. Honestly, things are not different in Pakistan than this. If they won, they will be honored like conquerors; but if failed, it will be harder to come back home.

Now with the invitation from Indian prime minister to Pakistani Prime minister and president to see the match, it seems that this match is going be a bit political. Unfortunately, Pakistani prime minister accepted this invitation which he shouldn’t as the game should be a game, not a political session.

Finally, both countries are having too many expectations from their teams, and are praying for their success. Let’s hope the game goes fair and the loser accept that from heart and doesn’t try to kill their team :)

Posted in Other | 1 Comment »


We are People, Not Programmed Device

March 19th, 2011


We are people, not programming devices

Posted in Other | No Comments »