StatCounter

View My Stats

Tuesday, February 10, 2009

Region based default button in ASP.NET

Region based default button in ASP.NET

Another one Simple Method is use the Panel inside it put the Default Button Focus To It
<!--


--!>

You can also kept the focus coding at the Form tag itself




If we want to provide the enter key focus based on the particular region we can use panel (or) form tag with "defaultbutton" properties.

Inside the panel you may kept anything else...table,div tag anything whatever u want to


Consider your cursor points to that's location on that if any enter key get fired then the default event focus to the control. For the above example the Button3 click event get fires on the enter key click event.

Getting the group of files from directory with the name specific

Getting the group of files from directory with the name specific


DirectoryInfo di = new DirectoryInfo("c:\\accounts");
FileInfo[] fArr = di.GetFiles("??A??.txt");
for (int iCounter = 0 ; iCounter <>
iCounter++)
{
string str = fArr[iCounter].Name;
}


For the above Example i am loading the group of files from the directory of "C:\\\accounts" with the file third letter of "A"

di.GetFiles("A??.txt");
For the above Example i am loading the group of files from the directory of "C:\\\accounts" with the file Name starts with the letter "A"

Random string generation in C#.Net

Random string generation in C#.Net

private string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch ;
for(int i=0; i
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
builder.Append(ch);
}
if(lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}

Dynamically load user control in ASP.NET Webform

Dynamically load user control in ASP.NET Webform


User Controls are semi-autonomous pages of HTML and underlying ASP.NET code that can be inserted into ASP.NET pages. As such they are useful for adding blocks of functionality to pages. Typical uses are to use User Controls for page headers and footers. They can also add functionality such as a "property of the week" for a real estate company website.

Unlike ASP.NET pages that have the .aspx file extension, User Controls typically have the .ascx file extension. Once created, in Visual Studio.NET they can be included in a specific page by simply dragging the user control onto the design view of that page. Alternatively, they can be added to a page at design time by including the following in the page's HTML. For example, the following line includes a header user control from the HeaderUserControl.ascx file:

<%@ Register TagPrefix="uc1" TagName="HeaderUserControl" Src="HeaderUserControl.ascx" %>

The header is then positioned on the page using the following tag:



Although this procedure is satisfactory for content like headers and footers that will always be required on specific pages, it would be useful if there was a way of dynamically loading specific user controls at run time. For example, an online store may only want a "clearance offers" section to appear if there is actually stock inventory in the database that has been marked as being for clearance.

Fortunately, it is possible to load user controls onto a page by making use of the LoadControl method. This function has a straightforward syntax - it takes a single argument - the virtual path to the user control page. For example, to load the featured product user control the following C# code would be used within the Page_Load method:





Control FeaturedProductUserControl = LoadControl("FeaturedProduct.ascx");




Once the user control has been loaded, it can be added to the page by adding it to the Controls collection:



Controls.Add(FeaturedProductUserControl);



The drawback with this technique is that it offers no control over where on the page the user control will actually appear. A useful tip is, therefore, to add a place holder control to the page in the position that you want it to display the dynamically loaded user controls. A place holder does just that - it acts as a container for other controls. You can then specify that the user control appear within the place holder by adding the user control to the place holder's controls collection:





PlaceHolderLeftMenu.Controls.Add(FeaturedProductUserControl);








Alternatively it is possible to position the user control in other ways, such as adding it to a Panel control:

PanelRightMenu.Controls.Add(FeaturedProductUserControl);

Creating a Cookie in ASP.NET

Creating a Cookie  in ASP.NET

#region Creating Cookies
HttpCookie JayaCookie = Request.Cookies["CookieExample"];
if (HttpContext.Current.Request.Cookies["CookieExample"].Value == null)
{
HttpContext.Current.Response.Cookies["CookieExample"].Value = Session.SessionID;
HttpContext.Current.Response.Cookies["CookieExample"].Expires = DateTime.Now.AddYears(30);
}
#endregion


For the above Example the cookie name is "CookieExample".I assigned the SessionID value to the cookie

Use of Sealed Keyword (or) Sealed Method

Use of Sealed Keyword (or) Sealed Method


The sealed method cannot be override at the derived class. it is mainly associated with the
override method.

For the below example at the DerivedSealed1 class the override function Base() associated with the "sealed" keyword.So it can't able to override the next level of inheritance.
For the below example the error thrown at the "DerivedSealed2 " override Base() Function.

If DerivedSealed1 the Base() override is not associated with the "sealed" keyword this wont thrown the error.

I hope that u can understand the use of "sealed Keyword"

public class BaseSealed
{
public virtual void Base()
{
Console.WriteLine("I am in Base Class");
}

}
public class DerivedSealed1 : BaseSealed
{
public sealed override void Base()
{
Console.WriteLine("I am in Derived Class 1");
}

}
public class DerivedSealed2 : DerivedSealed1
{
public override void Base()
{
Console.WriteLine("I am in Derived Class 2");
}

}

Difference between copy and clone in .NET

Difference between copy and clone in .NET

Copy:
_____

It copies both tha data and schema and the data.


Clone:
______

It copies the schema alone.And later we can add the rows belongs to it.

Which DLL handle *.aspx request?

Which DLL handle  *.aspx  request?


aspnet_isapi.dll Handles the *.aspx request.

Javascript File loading time in ASP.NET

Javascript File loading time in ASP.NET


U well know javascripts are running in the client machine. For example consider a ASP.NET web

form we used 2 javascript file means the client browser open and close a new connection for

loading each file from server to client.This will degrade performance of the page loading time .


So How big you are using the file is not a matter.The way of loading the file soon is important.

Example(1) 50 kb of a single file takes 6ms to load

A page load 3 javascript file.Those file total size is 20kb. This page takes 10ms to load

Page from server to client.

So Keep on considering how many files you are loading on a single page.This is one of the main performance issue.

Shell command in VBScript

Shell command in VBScript


'VBScript File
dim program
program="C:\Windows\System32\notepad.exe"
set oShell =CreateObject("wscript.shell")
oShell.Run(program)


For the above example i am running the system file through shell command

Taskkill.exe (Kill the task that running on local and remote machine)

Taskkill.exe (Kill the task that running on local and remote machine)


Examples:
TASKKILL /S system /F /IM notepad.exe /T
TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
TASKKILL /F /IM notepad.exe /IM mspaint.exe
TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"

U can run this command through process class in .NET

what is Wrapper?

what is Wrapper?


We overwrite the original function into user friendly function.That function is called as wrapper.


For Example below consider the original function have 5 argument and it process those five argument


public void originalFunction(string arg1,string arg2,string arg3,string arg4,string arg5)
{
//Some processing happening by the use of those parameter
}


For the above example consider if we only often need to send 3 parameters. we no need to send another 2 parameters.

We can create a wrapper function and internally get call that original function:

Example:

public void WrapperFunction(string arg1,string arg2,string arg3,"","")
{
originalFunction(string arg1,string arg2,string arg3,"","");
}


For above WrapperFunction is a "Wrapper" for originalFunction. Above we just hard coded the unnecessary last 2 arguments.

dotnet-sql-interview FAG: What is the MVC Pattern (Model View Controller Pattern)?

dotnet-sql-interview FAG: What is the MVC Pattern (Model View Controller Pattern)?