Archive for March 13th, 2008

Is it possible to prevent a browser from caching an ASPX page?

Thursday, March 13th, 2008

To call SetNoStore on the HttpCachePolicy object exposed through the Response object’s Cache property, as demonstrated here:
<%@ Page Language=”C#” %>
<%
Response.Cache.SetNoStore ();
Response.Write (DateTime.Now.ToLongTimeString ());
%>

SetNoStore works by returning a Cache-Control: private, no-store header in the HTTP response. In this example, it prevents caching of a Web page that shows the current time.

Posted by Mahesh ( Tryangled )

When Would you use Error Provider Control?

Thursday, March 13th, 2008

ErrorProvider control is used in Windows Forms application. It is like Validation Control for ASP.NET pages. ErrorProvider control is used to provide validations in Windows forms and display user friendly messages to the user if the validation fails.
Example: if we went to validate the textBox1 should be empty, then we can validate as below

1). You need to place the errorprovide control on the form

private void textBox1_Validating(object  sender,System.ComponentModel.CancelEventArgs e)
{
ValidateName();
}
private bool ValidateName()
{
bool bStatus = true;
if (textBox1.Text == “”)
{
errorProvider1.SetError (textBox1,”Please enter your Name”);
bStatus = false;
}
else
errorProvider1.SetError (textBox1,”");
return bStatus;
}

it check the textBox1 is empty . If it is empty, then a message Please enter your name is displayed.

Posted by Mahesh ( Tryangled )

How can we create custom controls in ASP.NET?

Thursday, March 13th, 2008

Custom Controls can be created in either of the following 3 methods.

1. Creating as a composite control : This method uses and combines the existing controls to give a custom functionality which can be used across different projects by adding to the control library. This can provide for event bubbling from child controls to the Parent container, custom event handling and properties. The CreateChildControls function of the Control class should be overridden for creating this custom control. This can also support design time rendering of the control.

2. Deriving from an existing control : This method of creating a custom control derives from an existing ASP .Net control and customizing the properties that we need. This also can support custom event handling, properties etc.,

3. Creating a control from Scratch : This method is the one which needs maximum programming. This method needs even the HTML code for the custom controls to be written by the programmer. This may also need one to implement the IPostBackDataHandler and IPostBackEventHandler interfaces.

Posted by Mahesh ( Tryangled )

Enumerate the types of Directives used in ASP.NET?

Thursday, March 13th, 2008

The following directives of enumerates used in ASP.NET

@ Page directive
@ Assembly directive
@ Import directive
@ Reference directive
@ Implements directive
@ OutputCache directive
@ Register directive

Posted by Mahesh ( Tryangled )