Monday, October 4, 2010
Disable right click on a web page
<HTML><HEAD>
<TITLE>ASP Web Pro</TITLE>
</HEAD>
<BODY>
<SCRIPT Language="JavaScript">
<!--
var message="Sorry, the right-click function is disabled.";
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// -->
</SCRIPT>
</BODY>
</HTML>
Sunday, October 3, 2010
Application configuration files in .net
configuration
/configuration
configuration
appSettings
add key="DatabasePath" value="c:\\projects\database.mdb" /
/appSettings
/configuration
used to access the contents of the configuration file. Since this class is part
of the namespace System.Configuration,
we have to use the fully qualified name System.Configuration.ConfigurationSettings.
As a shortcut, you can use the using directive
on top of the file like below:
using System.Configuration;
If you have the above directive on top of the file, then you can directly use
the class ConfigurationSettings.
web.config for web applications
The web applications use the same concept, but they use a config file with the name 'web.config'. There are couple of things to note in this case.
Saturday, October 2, 2010
Working with Cookies
" + Request.Cookies["MyCookie"]["Time"] + "";
" + Request.Cookies["MyCookie"]["Time"] + "";
" + Request.Cookies["MyCookie"]["Time"] + "";
" + Request.Cookies["MyCookie"]["Time"] + "";
Friday, October 1, 2010
Exception Handling
Thursday, September 30, 2010
ASP.net Page Life Cycle
ASP.NET determines that the page request by a user requires to be parsing and compiling or to render cached copy of the page to be send. Thus it comes very much before of the beginning of the page life cycle. After this, it is also checked that request is a normal request, postback, cross-page postback or callback. The page constructor creates a tree of controls as soon as the HTTP runtime instantiates the page class to perform the request.
Events
PreInit
This event is the beginning of the page life cycle. Every page controls are initialized and the properties are set according to aspx source code.
- Possible to Change or set Master page, Themes
- Creates or re-creates dynamic controls.
- Reads or sets Profile property values.
Init
First, the Init event for the Page object occurs, then Init event occurs for each control on the Page. Viewstate information is not available at this stage.
- Controls have been initialized zed
- Theme skins applied if any.
- Initialize control properties.
InitComplete
This event is used to processing tasks that require all initialization be complete.
PreLoad
This event is used before Perform any processing that should occur before Load. Use this event if you need to perform processing on your page or control before the Load event. Before the Page instance raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.
Load
Set properties in controls and establish database connections
Control Events
These are control specific events such as – Button Click, DropDownIndexChanged etc.
Load Complete
This event is used for performing those tasks which require load has been completed.
PreRender
In this event page insures that all child controls are created. Page calls EnsureChildControls for all controls, including itself. Every controls whose datasource/databind property is set calls for its databind method.
SaveStateComplete
This event occurs after viewstate encoded and saved for the page and for all controls.
Render
Every ASP.NET control has render method and the page instance calls this method to output the control’s markup, after this event any changes to the page or controls are ignored.
Unload
Unload event used to do cleanup task like closing the database connections, closing of the open files, completing logging or other requested tasks. Unload events occurs for each control on page control tree first and after that page.