Saturday, January 29, 2011

AJAX with ASP.NET

Imagine, you want to highlight a TextBox when the user moves the mouse over it. With the postback approach, you’d need to send the entire page back to the web server, regenerate it, and refresh it in the browser—by which point the mouse might be somewhere completely different. This approach is clearly impractical.

Ajax(Asynchronous JavaScript and XML)is programming shorthand for a set of techniques that create more responsive, dynamic pages. One of the hallmarks of Ajax is the ability to refresh part of the page while leaving the rest untouched.Ajax is nothing but JavaScript code that runs in the browser, requesting the new information from the web server when needed and updating the page accordingly.

The key benefit of Ajax is responsiveness, where as the challenges are code complexity and browser support.

TO use AJAX in ASP.net, we need to place a new web control ScriptManager on our page, and it’s the brains of ASP.NET AJAX .

If you’re using ASP.NET AJAX features throughout your website, you might choose to place the ScriptManager in a master page. However, this can occasionally cause problems, because different content pages may want to configure the properties of the ScriptManager differently. In this scenario, the solution is to use the ScriptManager in the master page and the ScriptManagerProxy in your content page. (You can find the ScriptManagerProxy on the same AJAX Extensions tab of the Toolbox.) Each content page can configure the ScriptManagerProxy control in the same way it would configure the ScriptManager.


All the elements and controls are kept between the tags.
When the UpdatePanel renders itself, it copies the content from the ContentTemplate into the page. This seems like a fairly unimportant low-level detail, but it does have one important side effect. If you want to use code to dynamically add controls to an UpdatePanel, you can’t use the UpdatePanel.Controls collection. Instead, you need to add new controls to the UpdatePanels.ContentTemplateContainer.Controls collection.

Friday, January 28, 2011

Registering the ASP.NET File Mappings: To run asp pages in IIS server

When a page is requested from the browser, that comes to the web server. The pages can be of different format i.e html, jsp, asp etc. The server is not the master of all for serving all types of pages.
At this point, one might be wondering how the web server knows when it needs to get the ASP or ASP.NET engine involved. Essentially, the web server looks at the file extension of the requested page (such as .asp or .aspx) to determine the type of content. The web server compares this extension against a list to determine what program owns this file type. For example, the web server’s list indicates that the .aspx extension is owned by the aspnet_isapi.dll component in the corresponding directory. The aspnet_isapi.dll component is known as an ISAPI extension, because it uses the ISAPI (Internet Server API) model to plug into the web server.

The easiest way to make sure you get the right version of aspnet_regiis is to rely on the Visual Studio Command Prompt. The Visual Studio Command Prompt is really just an ordinary Windows command prompt, but it sets the path variable so that the tools you need are at your fingertips. When you type aspnet_regiis.exe in the Visual Studio Command Prompt (without specifying a path), you’ll automatically run the correct version.
To start the Visual Studio Command Prompt, open the Start menu, choose Programs, and then choose Microsoft Visual Studio 2008 -->Visual Studio Tools -->Visual Studio 2008 Command Prompt.

Then for installing type the following
aspnet_regiis.exe -i


and then press enter.

If IIS is installed before installing Visual Studio, IIS is automatically configured for serving ASP pages by using asp engine. If not, then use the above code for configuring.

Monday, January 24, 2011

Add Date picker to ASP page from AjaxControlToolkit

Atfirst make a folder named i.e "Library" in your project folder. Then go to the References of Solution Explorer.

And Right Click-->Add References-->Select Browse--> Select the file from the location--> Add it.
Then add the text box, the target of the Selected Date. And also take a button or image by clicking which we will get our Calender.

The add the following code after the code of Button in the source view of the Form.

asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtBoxName" PopupButtonID="btnName"
Format="dd-MMM-yyyy"/>

Here the Format is used to define the format of your desired date to view.
After that, go to the next line of the FORM tag in your page. If you are using the Master Page as the part of your design. You will have to go to the FORM tag of your master page.Now you will have to add ScriptManager. For doing so, you will add the following line:


asp:ScriptManager ID="ScriptManager1" runat="server"/>


That's enough. You will get the Calender to pick the date.


IN this topic we have used code, but you can get this tool automatically from the Html portion of Toolbox menu. For doing so, you will have to Right Click on the lower part of Toolbox and then add the AjaxControlTool.dll from your made Library Folder. Then you will get these items from the Toolbox menu.


Click to get AjaxControlTool

Sunday, January 23, 2011

How to apply a Master Page to Existing Webpage OR Easily convert An Existing Web Form to a Web Content Form(with a Master Page)

Its our common behavior to change our web site on sparkle of our eyes. And for adding the banner or common things in each page is really difficult to perform. Concept of Master Page has handed over the freedom to us. For master page is the natural way to develop each web pages as the content page of the Master One. But We can ad our already
designed web page as the content page of the Master Page. Different way to say, we can apply Master Page o an existing Web page by following some steps.To convert from a Web Form to Web Content Form, all of the changes will occur in the Web Form’s aspx page.
just follow the following steps:

1.Create a Master Page
2.Apply Master Page via design mode in existing wen page
3.Copy over the Content Containers
4.In your Web Form, move Web Controls and information into the proper Content Containers.

Suppose, we have a web page named frmAddTask.aspx, we want to add the Master Page to this page. A s the part of above steps, we create the Master Page.
Then we need to go to the Design mode of our Web page frmAddTask.aspx, making the right-click we have to choose the properties for this page. From the properties, we select the Master Page option and show the Master Page we have created for this web page. Then in the code of the web page a small but vast change will be effected at the top line of its code view.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frmAddTask.aspx.cs" Inherits="SMS_IB_Support_tools.UI.frmAddTask" MasterPageFile="~/UI/SMS-IB.Master" %>


Now, the second and final step is to put items into the correct content boxes. The easiest and more error free to do this is to create a new blank Web Content Form, copy the content boxes from the Web Content Page, and paste them into our original Web Form. So right click the Master page in the Solution Explorer and select Add Content Page. Our example will output:

<%@ Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" Title="Untitled Page" %>





Copy lines 2-5 above and paste them into frmAddTask.aspx right below the “<%@ Page” directive. The ContentPlaceHolderID called ContentPlaceHolder1 will hold all the information between
in our "frmAddTask.aspx. The rest of the information below can be deleted.
We will must have to follow that, in the existing Web Page FORM tag is appeared. And in the Master Page also the
tag is available. Both of them can not be applied at the same time. So we will have to awakened to use the FORM tag of the master page only. Otherwise, we will get error message.

SOLID Principle

In computer programming, SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) is a mnemonic acronym introduced by Robert C. Martin in the early 2000s which stands for five basic patterns of object-oriented programming and design.




Single Responsibility Principle:
"There should never be more than one reason for a class to change."
If we have calculation logic and database logic and display logic all mixed up within one class it can be difficult to change one part without breaking others. Mixing responsibilities also makes the class harder to understand, harder to test, and increases the risk of duplicating logic in other parts of the design (decreases cohesion, functionality has no clear place to live).

Open Closed Principle:
"Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification."
The idea is that we can use OO techniques like inheritance and composition to change (or extend) the behaviour of a class, without modifying the class itself.Following the OCP should make behaviour easier to change, and also help us avoid breaking existing behaviour while making changes.

Liskov Substitution Principle:
"Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it."
It states that, if S is a subtype of T, then objects of type T in a computer program may be replaced with objects of type S (i.e., objects of type S may be substituted for objects of type T), without altering any of the desirable properties of that program (correctness, task performed, etc.).

Interface Segregation Principle:
"Clients should not be forced to depend upon interfaces that they do not use." The ISP is about keeping interfaces (both interface, and abstract class types of interfaces) small and limited only to a very specific need (a single responsibility even :)). If you have a fat interface then you are imposing a huge implementation burden on anyone that wants to adhere to that contract.

Dependency Inversion Principle:
"A. High level modules should not depend upon low level modules. Both should depend upon abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions."

The DIP says that if a class has dependencies on other classes, it should rely on the dependencies' interfaces rather than their concrete types. The idea is that we isolate our class behind a boundary formed by the abstractions it depends upon. If all the details behind those abstractions change then our class is still safe. This helps keep coupling low and makes our design easier to change.

Sunday, January 9, 2011

Gmail Modes

Many times, we are not able to access Gmail account from our PC for various reason. And that can not be performed for various issues. We can follow the modes depicted below for getting help on requirements.

Gmail Modes


If you can't access Gmail, try some of these URLs:

Safe mode - http://mail.google.com/mail/?labs=0. It disables the experimental features from Gmail Labs, just in case some of them are buggy. You can remove some of the features from Gmail's settings page.

Secure mode - https://mail.google.com/. It encrypts the traffic between your computer and Gmail's servers. Use it from public computers, Wi-Fi networks or to bypass some proxies and web accelerators. There's a Gmail setting that redirects the standard version to the secure mode ("Always use https").

Older version - http://mail.google.com/mail/?ui=1. This version has been replaced in October 2007 by a rearchitectured Gmail, but the old version is a little bit faster.

Basic mode - http://mail.google.com/mail/?ui=html. It's the version that doesn't use JavaScript, so it loads faster and it works well with older browsers. Unfortunately, many Gmail features are missing (contacts autocomplete, chat, spell checker, rich formatting) and each click loads a new page. If you like this version, click on "Set basic HTML as default view" at the top of the page.

Mobile mode - http://mail.google.com/mail/?ui=mobile or http://m.gmail.com. This is a simplified Gmail interface for mobile phones that has even less feature than the basic mode. Use it if no other Gmail mode works for you.

iPhone mode - http://mail.google.com/mail/x/gdlakb-/gp/. A more user-friendly mobile version for iPhone and other mobile phones that use WebKit-based browsers.

iGoogle gadget - http://www.google.com/ig/gmailmax. This is the canvas view for the updated Gmail gadget which can be found in the new iGoogle. Some people found that this interface bypasses most corporate filters that prevent them from accessing Gmail at work.

"No browser checking" mode - http://mail.google.com/mail?nocheckbrowser. If you use a cutting-edge new browser and Gmail serves you the basic HTML mode, try this URL to bypass browser detection.