Saturday, May 30, 2009

Adding Country Name to DropDwonList..

Objective:
This small application will describe how easily we can get all the country names and how easily we can show all the country names in a dropdown list by using asp.net with C#..

Problem:
In any registration page we need user should select Country from the dropdown list and for this we have to add Country Name one by one.. I think it’s very difficult to remember all the Country Name and add to dropdown list…

Solution: step by step
Step 1: Take one asp.net with C# application by using VS.Net 2.0;
Step 2: Design the form (Reg.aspx page)

Step 3: Go to Solution Explorer and add one folder named as App_Code



Step 4: Inside App_Code ->Add New Item-> add one class named as GetCountryNames.cs


Step 5: code inside GetCountryNames.cs file


Step 6: Code for Reg.aspx.cs file..



Step 7: Now Run your Application: (Output will be like this)..


Hope u enjoy this code....

Thursday, May 28, 2009

Disable Back button of Internet Explorer..

1: Purpose:

Some times we want user should not go back by clicking Back button of Internet Explorer. so here is the Java Script which we can write on master.aspx file in head section:

(Left Anchor Brkt) head (Right Anchor Brkt)
(Left Anchor Brkt) script language="javascript" type="text/javascript"(Right Anchor Brkt)
window.history.forward (1);
(Left Anchor Brkt) /script (Right Anchor Brkt)
(Left Anchor Brkt) /head (Right Anchor Brkt)

I m sorry to say the editor is not allowing Anchor bracket so u just implement..



2: Purpose:

Sometimes user should not go back after clicking logout Button..

protected void LinkLogoutBtn_Click(object sender, EventArgs e)
{
Session.Abandon();
Session["name"] = "";
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

Response.Redirect("logon.aspx");
}


Code description:
Here I write this code in Logout buton click event and when the user click logout i am clearing the cache and redirecting the user to Logon.aspx page..

Tuesday, May 26, 2009

Difference between finalize and dispose method

Use of Finalize method in .NET:
.NET Garbage collector performs all the clean up activity of the managed objects or we can say GC call the Finalize () function automatically to destroy the object called implicit destroy., and so the finalize method is usually used to free up the unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc.

Use of the dispose() method in .NET:
The Dispose method in .NET belongs to IDisposable interface and it is best used to release unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc from the memory. For betterPerformance we will use the dispose function explicitly.

Monday, May 25, 2009

Uploading filesize > 4MB using fileupload Control of ASP.Net

Problem:
While i try to upload .dat file which is more than 4MB i got one error message...

Reason:
In ASP.Net the default size of files uploaded by the FileUpload control is 4MB. So if you try to upload any file may be (.pdf, .doc, .wmv, dat..etc..) files larger than 4MB, it won't let you do so.

Solutions:
To do so, you need to change the default file size in machine.config.which is located in below pathC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory

//Add this code to machine.config file..
(use Left Anchor Brckt) httpRuntime
executionTimeout="90"
maxRequestLength="20000"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"/>

//or by adding one tag on web.config file
// Include the code below in your web application web.config

(use Left Anchor Brckt) system.web (use Right Anchor Brckt)
(use Left Anchor Brckt) httpRuntime executionTimeout="90"
maxRequestLength="20000"
useFullyQualifiedRedirectUrl="false"
requestLengthDiskThreshold="8192"/>
(left Anchor brkt) /system.web>

sorry to say this editor is not taking Anchor brackets so try to implement in code..




Bookmark and Share