Debugging JavaScript in User Controls

Little while back I was facing issue is debugging JavaScript code written inside an User Control (ascx) file in visual studio 2010.

Interesting thing is that breakpoints doesn’t work for User Controls in but you could still do the debugging if you write debugger; keyword before the line where you want to set the breakpoint. The visual studio will automatically detect this keyword in your code and would pause the execution at that line in debug mode.

But in my case even the debugger keyword was not working. Whenever visual studio designer used to encounter this keyword, VS used to halt at the first line of page’s markup (pagename.asps[dynamic]), and by this I could not find that exactly which of my debugger statement got hit.

The issue seems to be of the page’s temporary file/markup generated by VS.


deleted the website’s .pdb file from project’s bin folder and things started working.

Hope this information would help someone other there in coding world.


Visual Studio 2010 does not recognize asp tags

Visual Studio 2010 suddenly stopped recognizing asp tags in webpages. I don’t know the exact reason behind this behavior but I think it could be because of IE update (from 9 to 10), installing VS 2012 parallelly on same machine, or corrupted VS data files.

My development machine’s environment was

  • Win7 Professional
  • VS 2010 Professional
  • VS 2010 Professional SP1
  • VS 2012 Ultimate
  • SQL Server 2008 Express Management  Tools

I tried below mentioned workaround to fix the issue but no effect

  • Uninstalling the VS 2012 Ultimate
  • Revert back IE from 10 to 9
  • Repairing VS 2010 Professional SP1


Finally, deleting the C:\Users\UserName\AppData\Roaming\Microsoft\VisualStudio\10.0 folder resolved the issue.

Note: Replace the UserName with your logged-in username in above string.

Insert Update Binary data in MS Sql Server

It’s easy to insert update the Binary data from a .net application (web/windows).

But If you need to insert/update or copy/paste the data which is already there in the database then it’s not possible using the SSMS Table Editor (see attached image), it would give an error “The changed value in the call was not reognized as valid. .Net Framework Data Type: Byte[]
Error Message: You cannot use the Result pane to set this Field data to values other then null”.

Insert Update Binary data in MS Sql Server

Use the SSMS Query editor to do this, i.e.
update TableName set BinaryColumnName = BinaryData

Note: The binary data value should not be enclosed between any single quotes

Entity Framework Function Import not returning Columns data

While working with Entity Framework (EF), sometimes the EF doesn’t recognize the columns returned by the Stored Procedure.


1) If the db procedure is using temporary table (e.g. #tempTable), EF don’t recognize the MetaData from the procedure.

2) If multiple select … statements exists in db procedure.


Before executing procedure or beginning of db procedure set the FMTONLY to ON like below line:


This will force EF to read the metadata from Temp tables


There would be performance issues with approach because the way EF read the metadata from temp tables is to execute them multiple times.


Instead of using the temp tables, create table variables and use them to store data temporarily. While using this option you don’t need to set the FMTONLY setting.


Using the table variables will be faster than FMTONLY option.

Find more detailed information at


Run JavaScript after page is loaded

If you need to call a JavaScript code when the html page is completely loaded, you can use JQuery.

At times some controls are not rendered and the JavaScript code runs, hence it is  not able to find controls which is not rendered yet and client side code throws exception.

Use $(document).ready feature of JQuery as belows:

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


function showMsg()
// your code here


The above is also a replacement of the old body onload property: <body onload=”javascript showMsg()”> thing

Parameter is not valid. GDI exception

I was getting this exception while working with the GDI images in
My requirement was to upload the image from client then resize it and display.

The code was working fine on local development machine, but on production server it was throwing “Parameter is not valid” exception.

The general cause of this is that non-availability of resources required to generate a valid image file.

In my case the reason was that the destination folder was having read-only permissions, which was causing the code to hault while saving the processed image back to server.

For the resources I read during this issue, I found out some more reasons, these can be following:
1) Invalid source image path passed to the Drawing/Image/Bitmap object.
2) Invalid destination image path passed to the Drawing/Image/Bitmap object.
3) Corrupted/incomplete byte array.
4) Disposing of Source object before completing generation of new Image.
5) Folder write permissions while saving the new file.

Generic function to display images on webpage

Hi fellas,

I am writing this post after a long time. This new year I am back at blogging to help the software developers in writing better code .

Ever need of a generic/common function to display the images on website?
In normal practice, whenever we need to show an image, we used to directly write
Image.Src= “/userfiles/abc.jpg”;

This can be painful sometimes if your folder path gets changed,  in that case you need to replace the folder (userfiles) everywhere.

Smart and better way is to create a common function that will display images. What you need to do is to call this method every time.


public string ShowImage(string ImageName)
string ReturnVal = string.Empty;

if (File.Exists(System.Web.HttpContext.Current.Server.MapPath(“~/userfiles/” + ImageName)) == true)
ReturnVal = VirtualPathUtility.ToAbsolute(“~/userfiles/” + ImageName);
ReturnVal = VirtualPathUtility.ToAbsolute(“~/Images/ImageNotAvailable.jpg”);

return ReturnVal;


imgThumbnail.ImageUrl = ShowImage(“abc.jpg”);


This method, takes a string parameter as image name to display. Then it checks that if the particular image exists or not.
If the image exists on the specified path then it returns the image name with full path (userfiles/abc.jpg) else it returns the alternate image path, which is imageNotAvailable.jpg.

This way if the image is not founded on server then user will be shown a imageNotAvailable.jpg

Thats it for now.