DOT NET – How to make a button as default button and set Focus on a particular text box

In the initial days when i was new to development side and in some site i used to login straight away when i enter username and password and hit Enter key on my keyboard.

I used to think how is this happening but never had any answer but now i am going to show how thats possible.

In this post I will be talking about how  to make any button Default button and set Focus on a particular text box in any page thats displayed.

Ex: Make a test site and go to default.aspx

Step 1:

in <body> tag write the following code

<body>

<form id=”frmExample” runat=”server” defaultbutton=”btnLogin” defaultfocus=”txtUserName”>

<table><tr><td width=”50%”>

Welcome to the Example Web site from dilip

</td>

<td width=”50%”>

<table>

<tr><td><asp:TextBox ID=”txtUserName” runat=”server” Text=”UserName” /></td><td><asp:TextBox ID=”txtPassword” runat=”server” Text=”Password”/></td></tr>

<tr><td><asp:Button ID=”btnLogin” runat=”server” Text=”Login” onclick=”btnLogin_Click”/></td><td><asp:Button ID=”btnSignIn” runat=”server” Text=”Signup”/></td></tr>

</table>

</td>

</tr>

</table>

</form>

</body>

Note: Here the beauty is that i have login and singnup button and i made defaultbutton as login button, and defaultfocus on username text box so whenever this page is viewed from any web browser focus will be on username text box and default button will be login button so when u hit enter it will invoke login button so simple.

 Step 2: see  carefully i have a function onclick=”btnLogin_Click” now press F7 key and go to .cs side of the same page or right click on the mouse and select view code .

and write the following code in .cs side

protected void btnLogin_Click(object sender, EventArgs e)

{

Response.Write(“Default Button was clicked and u are now logged In”);

Response.End();

}

Note: Here another concept when ever you enter key this method will be invoked and at the same time there wont be any other you can see that means response is closed just to make you feel that you really logged in but actually u are in same page.

the output is some this like this :

First Time when visited:

you can see username text box is in focus.

Then when enter key is pressed:

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

JQuery Accordion

Accordion Functionality can be achieved by many ways one of the way is using jquery.

Name the above file as accordion.html and in the same folder jquery.js file.

you can download same for free from here.

and then have your custom according just waiting for you to use.

the output looks like this :

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

DOT NET 4.0 – Concerns and criticisms relating to .NET

Here are most known Criticisms

  • Applications running in a managed environment such as the Microsoft framework’s CLR or Java’s JVM tend to require more system resources than similar applications that access machine resources more directly. Some applications, however, have been shown to perform better in .NET than in their native version. This could be due to the runtime optimizations made possible by such an environment, the use of relatively well-performing functions in the .NET framework, just-in-time compilation of managed code, or other aspects of the CLR.

 

  • As JIT languages can be more easily reverse-engineered than native code to algorithms used by an application there is concern over possible loss of trade secrets and the bypassing of license control mechanisms. Many obfuscation techniques already developed, however, can help to prevent this; indeed Microsoft’s Visual Studio 2005 includes such a tool.

 

  • In a managed environment such as the Microsoft framework’s CLR or Java’s JVM the regularly occurring garbage collection for reclaiming memory suspends execution of the application for an unpredictable lapse of time (typically no more than a few milliseconds).

 

  • Since the framework is not pre-installed on older versions of Windows an application that requires it must verify that it is present, and if it is not, guide the user to install it.

 

  • Newer versions of the framework (3.5 and up) are not pre-installed on any versions of the Windows operating system. Some developers have expressed concerns about the large size (around 54 MB for end-users with .NET 3.0 and 65 MB with .NET 3.5).

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

 

DOT NET 4.0 – Features of DOT NET

Interoperability

Because interaction between new and older applications is commonly required, the .NET Framework provides means to access functionality that is implemented in programs that execute outside the .NET environment. Access to COM components is provided in the System.Runtime.InteropServices and System.EnterpriseServices of the framework.

 

Common Runtime Engine

Programming languages on the .NET Framework compile into an intermediate language known as the Common Intermediate Language (CIL). In Microsoft’s implementation this intermediate language is not interpreted but rather compiled in a manner known as just-in-time compilation (JIT) into native code.

 

Language Independence

The .NET Framework introduces a Common Type System, or CTS. The CTS specification defines all possible datatypes and programming constructs supported by the CLR and how they may or may not interact with each other. Because of this feature, the .NET Framework supports the exchange of instances of types between programs written in any of the .NET languages.

 

Base Class Library

The Base Class Library (BCL), part of the Framework Class Library (FCL), is a library of functionality available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions.

 

Simplified Deployment

Installation of computer software must be carefully managed to ensure that it does not interfere with previously installed software, and that it conforms to increasingly stringent security requirements. The .NET framework includes design features and tools that help address these requirements.

 

Portability

The design of the .NET Framework allows it to theoretically be platform agnostic, and thus cross-platform compatible. That is, a program written to use the framework should run without change on any type of system for which the framework is implemented. Microsoft’s commercial implementations of the framework cover Windows. In addition, Microsoft submits the specifications for the Common Language Infrastructure (which includes the core class libraries, Common Type System, and the Common Intermediate Language), the C# language to both ECMA and the ISO, making them available as open standards. This makes it possible for third parties to create compatible implementations of the framework and its languages on other platforms.

 

Memory management

It is the act of managing computer memory. In its simpler forms, this involves providing ways to allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed.

The management of main memory is critical to the computer system. In this process it uses the Garbage Collection which is the automated allocation, and deallocation of computer memory resources for a program.

This is generally implemented at the programming language level and is in opposition to manual memory management, the explicit allocation and deallocation of computer memory resources.

In computer science, garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory used by objects that will never be accessed or mutated again by the application. Garbage collection was invented by John McCarthy around 1959 to solve the problems of manual memory management.

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

Dot Net 4.0 – Windows Communication Foundation (WCF)

Windows Communication Foundation (WCF)

It is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. There are many other such technologies, including the Component Object Model and Distributed Component Object Model, Remote Method Invocation, Microsoft Message Queuing (MSMQ), and WebSphere MQ.

A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data. A few sample scenarios include:

  • A secure service to process business transactions.
  • A service that supplies current data to others, such as a traffic report or other monitoring service.
  • A chat service that allows two people to communicate or exchange data in real time.
  • A dashboard application that polls one or more services for data and presents it in a logical presentation.
  • Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.
  • A Silverlight application to poll a service for the latest data feeds.

While creating such applications was possible prior to the existence of WCF, WCF makes the development of endpoints easier than ever. In summary, WCF is designed to offer a manageable approach to creating Web services and Web service clients.

We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc

  • ASMX is IIS and HTTP only – WCF gives you HTTP, NetTcp, MSMQ, IPC – you name it

you can write your service once, and expose it on multiple endpoints

  • self-hosting: you can host your WCF service in a console app, a Winforms app, a WPF app, or let it be handled by IIS/WAS
  • a lot more options like reliable sessions, lot more security options
  • you don’t have to deal with as much in WCF as you do in ASMX – you can concentrate on your business problem, and let the config and attributes handle all the stuff you don’t want to deal with.

ASMX is:

  • easy and simple to write and configure
  • only available in IIS
  • only callable from HTTP

WCF can be:

  • hosted in IIS, a Windows Service, a Winforms application, a console app – you have total freedom
  • used with HTTP (REST and SOAP), TCP/IP, MSMQ and many more protocols

1)Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type.

2) web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends.

What Does WCF replace

ASMX, WSE, .NET REMOTING, COM+, MSMQ.

Rather than requiring different technologies for different communication styles, WCF provides a single unified solution.

1) Component Object Model (COM) It is used to enable interprocess communication and dynamic object creation in a large range of programming languages.

2) Distributed Component Object Model (DCOM) communication among software components distributed across networked computers.

3) MSMQ is essentially a messaging protocol that allows applications running on separate servers/processes to communicate in a failsafe manner.

4) WebSphere MQ is the most popular system for messaging across multiple platforms, including Windows, Linux, OS/2, IBM mainframe and midrange, and Unix. WebSphere MQ is often referred to as “MQ” or “MQ Series”.

5) Web Services Enhancements for .NET (WSE) is a product that enables you to build secure Web services quickly and easily.

6) .NET remoting enables you to build widely distributed applications easily, whether application components are all on one computer or spread out across the entire world

Architecture

WCF is meant for design and deploying distributed applications under SOA (Service Oriented Architecture) implementation.

WCF is designed in accordance with service oriented architecture principles to support distributed computing where services are consumed by consumers. Clients can consume multiple services and services can be consumed by multiple clients. Services are loosely coupled to each other. Services typically have a WSDL interface (Web Services Description Language) that any WCF client can use to consume the service, irrespective of which platform the service is hosted on. WCF implements many advanced Web services (WS) standards such as WS-AddressingWS-Reliable Messaging and WS-Security. With the release of .NET Framework 4.0, WCF also provides RSS Syndication Services.

Endpoints

A WCF client connects to a WCF service via an Endpoint. Each service exposes its contract via one or more endpoints. An endpoint has an address, which is a URL specifying where the endpoint can be accessed, and binding properties that specify how the data will be transferred.

The mnemonic “ABC” can be used to remember address/binding[disambiguation needed]Contract. Binding specifies what communication protocols are used to access the service, whether security mechanisms are to be used, and the like. WCF includes predefined bindings for most common communication protocols such as SOAP over HTTP, SOAP over TCP, and SOAP over Message Queues, etc. Interaction between WCF endpoint and client is done using a SOAP envelope. SOAP envelopes are in simple XML form that makes WCF platform independent.

When a client wants to access the service via an endpoint, it not only needs to know the contract, but it also has to adhere to the binding specified by the endpoint. Thus, both client and server must have compatible endpoints.

With the release of the .NET Framework 3.5 in November 2007, Microsoft released an encoder that added support for the JSON serialization format to WCF.[1] This allows WCF service endpoints to service requests from AJAX-powered Web pages.

APPLICATION

The rental car reservation application provides WCF-based services that can be accessed by various clients.

Unification of Microsoft’s Distributed Computing Technologies

Think about the team of developers implementing the rental car reservation application described earlier. In the world before WCF, this team would need to choose the right distributed technology from the multiple choices originally offered by the .NET Framework. Yet given the diverse requirements of this application, no single technology would fit the bill. Instead, the application would probably use several of these older .NET technologies. For example:

1)  ASMX, also called ASP.NET Web Services, would be an option for communicating with the Java EE-based reservation application and with the partner applications across the Internet. Given that Web services are widely supported today, this would likely be the most direct way to achieve cross-vendor interoperability.

2) .NET Remoting is a natural choice for communication with the call center application, since both are built on the .NET Framework. Remoting is designed expressly for .NET-to-.NET communication, so it would offer the best performance for this situation.

3) Enterprise Services might be used by the rental car reservation application for things such as managing object lifetimes and defining distributed transactions. These functions could be useful in communicating with any of the other applications in this scenario, but Enterprise Services supports only a limited set of communication protocols.

4) Web Services Enhancements (WSE) might be used along with ASMX to communicate with the Java EE-based reservation application and with the partner applications. Because it implements more advanced SOAP-based standards, known collectively as the WS-* specifications, WSE can allow better security and more, as long as all applications involved support compatible versions of these specifications.

5) System.Messaging, which provides a programming interface to Microsoft Message Queuing (MSMQ), could be used to communicate with Windows-based partner applications that weren’t always available. The persistent queuing that MSMQ provides is typically the best solution for intermittently connected applications.

6) System.Net might be used to communicate with partner applications or perhaps in other ways. Using this approach, developers can create applications that use the HTTP-based communication style known as Representational State Transfer (REST).

If it were built on an earlier version of the .NET Framework, the rental car reservation application would need to use more than one of these communication technologies, and maybe even all of them, to meet its requirements. Although this is technically possible, the resulting application would be complex to implement and challenging to maintain. A better solution is needed.

WS – Protocol Support

Security, Reliable Messaging, Transactions, Metadata, Messaging, XML.

Where it can be used

business-to-business (B2B)
business-to-consumer (B2C),
Interoperability with other platforms and technologies
messaging for any kind of communication
Routing
and for all the kind of services that were earlier developed using ASMX, WSE, Web Services, MSMQ, and distributed stack. It also helps in creating the distributed application in a very easy manner that earlier would have involved the usage of two or more distributed technology. These custom solution were earlier not possible to develop in either web services or .NET Remoting. WCF facilitates in building these custom solutions. WCF provides a Uniform programming model to creating distributed applications and has been designed to support  Service orientation… many more

Performance Characteristics

In most cases these can be used but might change according to the requirement.

Note : This article is written taking reference from msdn and other standard microsoft sites just to give a clear Idea how this technology works i have compiled into one, also my personal views are written this should not be taken for granted.

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

DOT NET 4.0 – Versions and Features

Versions

1.0, 1.5, 2.0 (ECMA), 3.0

Features

C# differs from C and C++ in many ways, including:

  • There are no global variables or functions. All methods and members must be declared within classes. It is possible, however, to use static methods/variables within public classes instead of global variables/functions.
  • Multiple inheritance is not supported, although a class can implement any number of interfaces. This was a design decision by the language’s lead architect to avoid complication.
  • Full type reflection and discovery is available.

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )