Tag Archives: Asp.Net

Debugging JavaScript in asp.net User Controls

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

Interesting thing is that breakpoints doesn’t work for User Controls in asp.net 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.

Solution

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.

Thanks


Visual Studio 2010 does not recognize asp tags

Visual Studio 2010 suddenly stopped recognizing asp tags in asp.net 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

Solution

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.


Parameter is not valid. Asp.net GDI exception

I was getting this exception while working with the GDI images in asp.net.
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.


URL rewriting using Global.asax, Error: The resource cannot be found.

Today I implemented my first application having URL rewriting enabled.
The application is created in Asp.net, C# and MS Sql 2005.

The url rewriting logic was working on the my localhost but it didn’t worked on production server.

I was getting an error: The resource cannot be found. while accessing the newly created URL pages.

I searched on Google about this and read lot, but nothing worked.

Finally I re-published the website and again uploaded all the files to production server and now everything worked like magic. Here is the URL: http://theplayclan.com/blog

Somewhere I read to check the permissions on server’s IIS, this method is explained below:

1) Open IIS manager.
2) Right click on your website’s virtual directory, select Properties.
3) Now, click on Configuration (in front of execute permissions option).
4) In the new popped-up window a list comes up as Application Extensions.
5) select .aspx option and click on edit.
6) Make sure that the Verify That File Exists is unchecked. This option explicitly check for the existence of file.
7) Save the settings and try again.

Somewhere it was mention to remove the *.* and regular expression extension mappings from the IIS may also work. The procedure of this is mentioned above.


Traverse / Loop through all form controls in asp.net

This post explains that how to traverse (loop through) all form controls in asp.net page.

foreach (System.Web.UI.Control ctrl in this.form1.Controls)
{
//here your code
}

Further if you want to get the state or data or manipulate the control, use the below code:
Here I am checking that at least one DropDownList item is selected out of all DropDownLists in the current webform.

bool isSelected = false;

foreach (System.Web.UI.Control ctrl in this.form1.Controls)
{

if (ctrl.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
{
DropDownList ddl = (DropDownList)ctrl;

if (ddl.SelectedItem.Text != "")
{
isSelected = true;
break;
}
}

}

if (isSelected == true)
{
Response.Write("selected");
}
else
{
Response.Write("none selected");
}


Access your Asp.Net application over LAN

This post explains how to access some Asp.Net Application residing on another machine on network.

First of all you computer must be in the same workgroup as of the target computer. Then enter the following URL in the internet browser:

http://192.168.1.84/myWebsiteTest/default.aspx
or
http://ajay/myWebsiteTest/default.aspx

Here instead of ajay/192.168.1.84 you have to enter either the IP Address or the name of the computer on which asp.net application resides.

Just hit the enter key and you will see the output.

Happy Programing……..


MyBase in VB.Net is equal to base in C#

The Mybase object of VB.Net is similar to the base in C#.

So while using C# use “base” instead of “MyBase”.

Happy Programing……