ads

Tuesday, June 23, 2009

Prevent a Class to be inherited C#

The sealed can be used to prevent a class to be inherited.

sample:
    sealed class FileClass
    {
        sealed FileClass(string filepath)
        {
            Filepath = filepath;
        }
   
        private string _filepath;
        public string Filepath
        {
            get { return _filepath;}
            set { _filepath = Filepath; }
        }
    }

Thursday, April 16, 2009

Display All Server Files in Server using C# and ASP.NET

DirectoryInfo di = newDirectoryInfo(Server.MapPath("/"));

FileInfo[] fi = di.GetFiles();

fi = di.GetFiles("*.*");

foreach (FileInfo fi1 in di.GetFiles())

{

Response.Write( fi1.FullName.ToString());

Response.Write("<br />");

}

Wednesday, April 8, 2009

Cross-Page Posting ASP .NET

Make 2 forms name it page1.aspx and page2.aspx

on page1.aspx:

Add a TextBox and Button Control

Go to the Button Control Properties and set the PostbackUrl = "~/page2.aspx"

on Page2.aspx:

Add a Label Control and on the Page_Load Event add this following code.

protectedvoidPage_Load(objectsender, EventArgs e)

{

if (PreviousPage != null)

{

if (PreviousPage.IsCrossPagePostBack == true)

{

Label1.Text = "Cross-page post.";

TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1");

this.Title = tb.Text;

}

}

else

{

Label1.Text = "You are not allowed to access this page!";

}

}

Monday, November 3, 2008

Prevent Multiple Click on Saving in ASP.NET

This a very simple task all you have to do is just disable the Save button used in saving the data..

protected void saveButton_Click(object sender, EventArgs e)
{
//to prevent multiple click disable the button
saveButton.Enabled = false;
//-------------------
//Put code to save data
//------------------
//Data is no save so its now okay to enable the button
saveButton.Enabled = true;
}

Google Search