Thursday, January 24, 2008

Handle default button event in Asp.Net 1.1.

Asp.Net provide the easy way to handle default button event,with asp.net you have write your own code to fire the button event on "Enter" key hit.
Here is two method to handle it.
1)Write this code on page load event.
Page.RegisterHiddenField("__EVENTTARGET", btnSearch.ClientID);

2)txtSearch.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+btnSearch.UniqueID+"').click();return false;}} else {return true}; ");

Here
txtSearch is the name of textbox and btnsearch is the asp button.

Tuesday, January 22, 2008

"Unable to start debugging on the web server. You do not have permission to debug the application. The URL for this project is in the Internet zone."

You may receive the error "Error while trying to run project: Unable to start debugging on the web server. You do not have permission to debug the application. The URL for this project is in the Internet zone. Click Help for more information."

This is one of the various errors that appear when you are debugging and may haunt you until you do the following fix:-

1. In the Internet Explorer, "Tools" Menu, select "Internet Options".

2. Switch to "Security" Tab.

3. Click on "Internet" (The Globe Icon. Its actually the default selected).

4. Click on "Custom Level" in the bottom.

5. Scroll down to find the "User Authentication" section.

6. Select "Automatic logon with current username and password".

7. Click "Ok" twice to exit.

This should solve the issue.

There are various reasons you get the "Unable to start debugging on the webserver". For a complete list of solutions, please check http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vsdebug.asp

Wednesday, January 16, 2008

How to maintain the position of the scrollbar on postbacks (across the entire site)

If you would like to apply this behavior to your entire site simply make a entry in your web config file
Click to see full image;






How to set the default focus to a control when the page loads

form id="frm" DefaultFocus="txtUserName" runat="server"

On way to know "How much time your function will take during execution"System.Diagnostics.Stopwatch

System.Diagnostics.Stopwatch is a replacement for what most people probably do to identify the time spent on excecuting a method.

System.Diagnostics.Stopwatch watch=new Stopwatch();
watch.Start();
//body of function
watch.Stop();
showduration.Text = "Time Spent for function body execution" + watch.Elapsed.ToString();

Speed up Visual Studio 2005

  • Make sure Visual Studio 2005 SP1 is installed.
  • Turn off animation.Go to Tools Options Environment and uncheck Animate environment tools.
  • Disable Navigation Bar.
  • If you are using ReSharper, you don't need VS2005 to update the list of methods and fields at the top of the file (CTRL-F12 does this nicely). Go to Tools Options Text Editor C# and uncheck Navigation bar.
  • Turn off Track Changes.
  • Go to Tools Options Text Editor and uncheck Track changes. This will reduce overhead and speeds up IDE response.
  • Turn off Track Active item.
  • This will turn off jumping in the explorer whenever you select different files in different projects. Go to Tools Options Projects and Solutions and uncheck Track Active Item in Solution Explorer. This will ensure that if you are moving across files in different projects, left pane will still be steady instead of jumping around.
  • Turn off AutoToolboxPopulate.
  • There is an option in VS 2005 that will cause VS to automatically populate the toolbox with any controls you compile as part of your solution. This is a useful feature when developing controls since it updates them when you build, but it can cause VS to end up taking a long time in some circumstances. To disable this option, select the Tools Options Windows Forms Designer and then set AutoToolboxPopulate to False.
  • Disable "Start Page".
    Go to Tools Options.
    In Environment Startup section, change At startup setting to Show empty environment.
  • Disable splash screen.
    Open the properties of Visual Studio 2005 shortcut.
    Add the parameter /nosplash to the target.
  • Close all unnecessary panels/tabs to prevent them from appearing when the IDE loads.

Monday, January 7, 2008

Remove HTML from your code with Regular expression.

C# code :

Regex.Replace(lContent, "<[^>]*>", "");
lContent is the string that contained HTML

Friday, January 4, 2008

How to deploy ASP.NET web application on the live server

In order to deploy Asp.Net(Version 1.1) web application to the live server follow these steps:

Requirement: 1) FTP(File Transer Protocol) details.
It contain the login credentials "Username" and password.
These are required to login on remote server.
2) Any software that establish a connection between client machine and server.
>Filezila
>ws_FTPpro (you can use any one of these)
If you do not have download from the following link:
http://www.soft32.com/download_94584.html
http://www.download.com/3000-2160_4-10771265.html
http://filezilla-project.org/
3) Your web site code that is complied.
There is some difference when we are going publish website from as.net(Version 1.1) and asp.net(Version 2.0)
In Case of ASP.NET ( Version 1.1). Follow these steps:
Step1: Rebuild your web site in the "release"mode. The benefit of this mode is that it remove all break points if there is any in your project. (Make a separate copy of your project)
Click to see full image



step2: Now delete the file having following extention:

  • .sln
  • .cs
  • .suo
  • .resx
  • csproj

Do not delete having .aspx, .asax, .webinfo, .config extenstion.
Now transfer the the final folder to the server with the help of any software that provide the interface between your client machine and server. Its interface will look like this:

Click to see full image










Left hand side will show the client machine and right side will show the server machine. Now you can simply select the folder from the client machine and transfer to the server.(For transfer you should have login credential of the server)

Note in the future if you.

  • Made changes in .cs (in any dll)file in that case you have to build your project again and replace the dll that is in the bin folder of your project after build and replace with that is on the live server.
  • Made changes in web config(or .aspx file) file then in this case you do not have any need to replace any other file simply replace web config file.

Deploy web application in ASP.NET (2.0)

In Asp.Net(2.0) is very easy you donot have any need to delete these files.(already deleted)



Simply Go Build and select the option publish Web Site and give the folder name where you want to place the final build. When the publish process is complete you can transfer to the live server.


Unable to evaluate expression because the code is optimized.........

Error: "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
You get such type of exception when you are using server.transfer(); or response.redirect() on your .cs or .vb page
For knowing the symptoms and solution follow this link:
http://support.microsoft.com/kb/312629/EN-US/

Thursday, January 3, 2008

While Deploying Asp.Net Application

After developing a site either in Asp.net(ver.1.1) or Asp.net(ver.2.0), you are going to deploy it on the live server or deploy it on test server. During the deployement process some time you may face different types of error. Different types of error have different types of solutions.
These are the list of error and their respective solutions.

Case 1: Error "Server application is unavailable "
Solution : This Type of error occured because on your system two or more dot net framework is installed and your application that is deployed on the server is pointing to wrong framework .
Steps to resolve this issue:1)Open your IIS setting and go the property tag of your application and choose the ASP.NET tag as shown in the Pic.


















2) Choose the Asp.Net version(Using which your application is developed).

3)Click on apply button.
Case 2: Error. "Server Error in 'virtual directory name' Application Server cannot access application directory 'C:\virtual directory name \' the directory does not exist or is not accessible because of security settings."
Or
Access denied to c:\''Virtual directoryname\'' Failed to start monitoring file changes
Solution: This error is due to the security settings on your application folder. Follow these steps:
1).Right click the folder and go to the properties of the folder. You will see the new window like this.
Add to user give them full rights
everyone
aspnet
case 3: "The project 'project name' is on an untrusted web server. Opening this project may cause code to be executed with full trust. Do you want to continue opening this project ? If you donot trust source of this project , If you do not trust the source of this project , you should choose 'No'"


Click to see full image.

Solution :Follow this step.
1) Restart your IIS.