Banner Ad

Sunday, December 21, 2014

An easy way to construct the Connection String in ASP.Net

By Francis   Posted at   7:26 AM   Connection String 2 comments

Connection strings are necessary when you want to interact with any databases like SQL Server, MSAccess etc. Most probably if you are using ADO.Net Concepts to interact with Database then you can aware about the connection string. In this article I am going to share how it can be easily constructed.

 

Step 1:

Open Visual Studio and create sample web form application.

 

Step 2:

Switch over to “Design Mode” and in the tool box, just drag and drop a “Gridview” control in to the web form.

DesignMode-1

 

Step 3:

Select “New Data Source”.

DesignMode-2

Step 4:

In the “Data Source Configuration Wizard”, select your database click “OK”.

Datasource-1

Step 5:

In the next step of the wizard, Click “New Connection”.

Datasource-2

Step 6:

It will provide a pop-up dialog box to select “Data Source”, in that select “Data Source” and select data provider from “Data Provider” dropdown list, then click “Continue”.

Datasource-3

Step 7:

In “Add Connection” modal dialog, select your “Server Name” (if not available, first click “Refresh” button, still it not available type your “SQL Server Name” manually on it).

You can either use, “Windows Authentication” or “SQL Server Authentication” to login to your SQL Server.

As a next step, select your database, that is available on your SQL Server. Finally, click “Test Connection”, to check whether the connection is established successfully or not.

Datasource-4

 

Datasource-5

Step 8:

As a final step, you will get the Connection string, which can be used on your web/windows application to connect the DB.

Datasource-6

Happy Coding!

Saturday, December 20, 2014

ASP.Net MVC – Create Custom HTML Helpers

By Francis   Posted at   11:52 AM   Razor No comments
Html Helpers are classes that helps to render HTML controls in Views. We can also create our own HTML Helpers. In this post, I’m going to explain how to create a simple Custom HTML Helper. The main purpose creating custom HTML helper is reuseability.

Step 1:
          Create a static class and add method to it like below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVCTutorial
{
    public static class CustomHTMLHelper
    {
        public static MvcHtmlString ImageLink(string action, string controller, string imgageURL)
        {
            // Create a link with an image
            return MvcHtmlString.Create(String.Format("<a href=\"{1}\\{0}\"> <img src=\"{2}\" /></a>", action, controller, imgageURL));
        }
    }
}

     
Step 2:
          Access the custom helper class in a View.
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Sample</title>
</head>
<body>
    <div>
        @CustomHTMLHelper.ImageLink("Home","Account","your image url")
    </div>
</body>
</html>


The helper class is static, since it can be called in a easy manner also handy.
Happy coding!

Tuesday, December 9, 2014

Design Pattern - An Introduction

By Francis   Posted at   5:08 PM   Design Pattern No comments

                                  Few weeks ago, I commit to take an session about design pattern in my organization. As a matter of fact, I’m not a big fan of design pattern. However, I began dwell with design pattern, I found interesting on it. So I decided to write some posts on it. In this post, I just give an introduction about design pattern.
So what is design pattern?

                                 Design Pattern are conceived by the 4 people who wrote the book "Design Patterns: Elements of Reusable Object-Oriented Software ".  Design pattern is a proven ways to solve the particular problem while arising often writing software programs. Those problems are frequently encountered by the programmers, most probably when design the software.  So there is no reinvent the well again. There are 23 solutions predefined by the above authors. Each problem has its own name also.
The ultimate goal:
There is no reinvent of solution for the 23 problems. Also the main benefit is maintainability of software. If you want to change something in the existing system it is so easy. The above are the main benefits of design pattern. These 23 design patterns are called Gang Of Four in general.
                           They are categorized into 3 types. They are: 1. Structural Pattern 2. Creational Pattern 3. Behavioral Patterns

The category name itself enough to explain, the purpose of each pattern. For example, Creational patterns are talk about the object creation. At the same time structural pattern described about code structure. Below are the 23 design patterns.

 

Creational Patterns:

  1. Abstract Factory
  2. Singleton Pattern
  3. Builder Pattern
  4. Factory Method Pattern
  5. Prototype Pattern

 

Structural Patterns:

  1. Flyweight Pattern
  2. Proxy Pattern
  3. Adapter Pattern
  4. Bridge Pattern
  5. Facade Pattern
  6. Composite Pattern
  7. Decorator Pattern
  • Behavioral Patterns:
    1. Chain of Responsibility
    2. Observer Pattern
    3. Command Pattern
    4. Interpreter Pattern
    5. Iterator Pattern
    6. Visitor Pattern
    7. Template Pattern
    8. Strategy Pattern
    9. Memento Pattern
    10. Mediator Pattern
    11. State Pattern

Sunday, October 5, 2014

ASP.Net Forums–FAQ #6: ASP.Net Session Expired Problem

By Francis   Posted at   12:29 AM   IIS Tips and Tricks 1 comment
session_expired
Most of the asp.net application using session, especially data driven applications. Mostly these kind of application using “Inproc” mode of session. During development the developer does not face any kind of problem with the session. When deploy the application the problem arise one by one. In this post I just want to share some thoughts and my professional experience on this issue.

Saturday, September 27, 2014

How to disable the “tooltip” for a Asp.net control programmatically?

By Francis   Posted at   12:31 AM   ASP.Net with Javascript No comments
One of the forum member ask this question in the asp.net forum. The answer is yes, we can use a simple javascript to achieve this functionality. Take a look at the below code:
Using Javascript:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function DisableToolTip() {
            // Get the object
            var obj = document.getElementById('LnkBtn');
            // set the tool tip as empty
            obj.title = "";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:LinkButton runat="server" Text="Simple Link Button" ToolTip="Simple Button with Tool Tip" ID="LnkBtn" ClientIDMode="Static" ></asp:LinkButton>
    <a href="#" id="lnkDisable" onclick="DisableToolTip();">Disable Tool Tip</a>
    </form>
</body>
</html>

Using JQuery:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#lnkDisable").click(function () { $('#LnkBtn').attr({'title':''}); });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:LinkButton runat="server" Text="Simple Link Button" ToolTip="Simple Button with Tool Tip" ID="LnkBtn" ClientIDMode="Static" ></asp:LinkButton>
    <a href="#" id="lnkDisable">Disable Tool Tip</a>
    </form>
</body>
</html>

Monday, September 15, 2014

ASP.Net Forums - FAQ #5: How to change the Title Case of a string to Uppercase in Server Side?

By Francis   Posted at   12:04 PM   ASP.Net Forums No comments
One of the user in the forum asked similar to this question. In server side, I thought take the string, and covert it to character array and loop thru the character and change the first Letter alone to capital letter.
                     Instead,we can use “TextInfo” class to achieve the solution in a easier manner. The below function used to convert the given string’s first character alone as a Capital letter.

       
        using System.Globalization;
        using System.Threading;
        public string changeName(string inputname)
        {
            string modifiedname = string.Empty;
            string[] names = inputname.Split(' ');
            foreach (string name in names)
            {
                    CultureInfo cultureInfo   = Thread.CurrentThread.CurrentCulture;
                    TextInfo txtinfo = cultureInfo.TextInfo;
                    string temp=txtinfo.ToTitleCase(name);
                    modifiedname = string.Concat(temp, " ");
            }
            return modifiedname;
        }

Wednesday, August 27, 2014

Settled with Cognizant!!!

By Francis   Posted at   7:08 AM   General No comments

NewJob

           After a last couple of month (serious Smile) job hunt ended with an offer with Cognizant, an multinational IT giant in India. As a asp.net blogger, I missed out a lot for the last few months. Hope this change will make a difference in all aspects. At the same time, I want to thank my previous company colleagues and friends for their wonderful support during my tenure there.  Be cognizant!!!

Thursday, July 17, 2014

Daily Interview Question #14 : What is Cross-Page Posting?

By Francis   Posted at   1:22 PM   ASP.Net Interview Questions No comments

Cross page posting is used to submit a page (page1.aspx) to another page (page2.aspx). However, the user can still able to access the first page’s (page1.aspx) controls, properties etc in the second page (page2.aspx). In order to access the first page’s control, we have to use “Previouspage” property.

Sunday, July 13, 2014

Daily Interview Question #13 : What is “Postback”?

By Francis   Posted at   4:42 PM   ASP.Net Interview Questions No comments

                     In ASP.Net postback means, page posted back itself to the server(IIS) whenever an event triggered. That is, page is submitted to the same url. The event may be a button click or dropdown list changed etc. Postback can be identified by IsPostBack() property, to detect the page object is created due to postback.

Tuesday, July 8, 2014

Daily Interview Question #12 : What is the purpose of “sealed” keyword in C#?.

By Francis   Posted at   6:31 PM   C# Interview Questions No comments
Sealed
1. When you want to prevent an class from being inherited by another class, you should use “sealed” keyword in front of the class.

Wednesday, June 25, 2014

Daily Interview Question #11 : What are the different Session Modes available in ASP.Net?

By Francis   Posted at   5:07 PM   ASP.Net Interview Questions No comments
                              In ASP.Net, “Session Mode” denotes where the ASP.Net application is going to store the user session information.  This can be specified in the Web.Config file by the “SessionState” config element under the “System.Web” config Element.

Sunday, June 1, 2014

Daily interview Question #10 : what is the purpose of "explicit" implementation of interface?

By Francis   Posted at   7:32 AM   CodeProject No comments

There are 2 purposes of explicit implementation of Interface:
First, it is used to avoid name collision between interface methods. That is if you are going to create a class library, there may be a chance to use the same name in several places. At that time "explicit" implementation comes as a rescue.
Secondly, You cannot access that implemented method through the object of the class directly. Instead you typecast it as Interface reference then you can access it. This is because, the C# complier, unable to determine which one the user want to call.

Friday, May 16, 2014

Daily interview Question #9: what is the purpose of ref and out parameters in C#?

By Francis   Posted at   9:00 AM   No comments

          Ref keyword is used to send the particular parameter as a reference to the function or subroutine.
          In some cases we may want to return value from the function but we don't want to use that variable within the function. We just get back some value, that's all. In these kind of scenarios we may go with 'out' parameter.
          The main difference between the two is, before passing ref parameter we must initialize the particular variable. But this kind of initialization is not necessary with 'out' parameter.

Sunday, May 11, 2014

ASP.Net Forums - FAQ #4 : Running ASP.Net website from Home

By Francis   Posted at   3:20 PM   ASP.Net Forums 1 comment
                                           Here is the next question for a newbie who are wish to run a ASP.Net website from home or going with a hosting company. However, as per my experience I suggest to instead of running website from home, you may prefer a good hosting company. Running a website from home is not a bad idea. But the stuff behind it some what hard. So in this article i am going to highlight what are the stuffs you need to run a website.
WebSiteIdea
                                 

Thursday, May 1, 2014

A List of Developer Tools : A Tech blogger must have

By Francis   Posted at   6:27 PM   Blogging No comments
                    I Love Technology blogging. Since the beginning of this blog, I have lot of troubles to write my articles, to show my output of my demo, Convert code from vb.net to C# and vice versa etc. So some useful stuffs and utilities needed for me which simplify my day today blogging activities. In this post, I am going to guide you these kind of useful stuffs.
Blogging_Tools

Monday, April 21, 2014

File Upload Control–How to give same UI in all browsers?

By Francis   Posted at   6:56 PM   CodeProject No comments
                                  As all of know, the File Upload control is used to upload your favourite files to the server. One of the biggest challenge while using this control is UI issue. That is this control is rendered in a different ways in all browsers. Please see the below figures, each of them rendered the File Uploader in a different way. That is UI is vary across the browsers.

Friday, April 18, 2014

ASP.Net Forums - FAQ #2 : ASP.Net Project Ideas

By Francis   Posted at   8:17 AM   ASP.Net Forums No comments
how-to-start-project
                                              ASP.Net Forums have tons of Questions. I have preferred some most frequently questions and give a detailed explanation here. This one also I encountered a lot in the ASP.Net Forums. Most of the college students and beginners are asked about the below questions:
How to start an ASP.Net Web Projects?
Where to get some basic ideas about web based projects?
                    In this post I just want to guide those people from my practical experiences.

Prerequisite – Software:
                Before start your project you need the below softwares:
  1. Visual Studio
  2. .Net Framework
  3. SQL Server   
                        For students and beginners express version of visual studio is enough. While this writing Microsoft released Visual Studio 2013. You can download the Visual Studio 2013 express for web development here. With that installation, .Net framework 4.5 also installed. So there is no separate download is not necessary.
                         Each and every website that are developed are data centric or data driven. That are data are stored and retrieved from a database like SQL Server. So you must need that one also.
                         For SQL Server also Microsoft provide express version. You can get it SQL Server 2008 Express with SP2 here and SQL Server 2012 here.
                        For the above software installation you must need Windows 7 with SP1 or Windows 8.
Prerequisite – Skills:
              The below are the must have skill sets that are required for every beginner in ASP.Net.
  1. .Net Architecture (CLR and BaseClass Library)
  2. C# or VB.Net Language
  3. ADO.Net
  4. ASP.Net (Web Form, Worker Process, AppDomain, Session, Cache, Authentication etc)

               It is better how the .Net frameworks works which helps to the developer to grasp the rest of the things easily. If you want to go with ASP.Net you should learn any one of the .Net compatible language such that C# or VB.Net. ADO.Net always deals with Database related objects like Datasets, Datatables etc. In beginner level choosing Web Form will give a easy to move way in ASP.Net. The above lists are specific to .Net.

Some Good Books for ASP.Net:
         Below are my personal suggestion to sharpen your skills in ASP.Net as well as .Net Languages such as C# and VB.Net in some extend.

  1. Programming ASP.Net By Dino Espotio (From Microsoft Press)
  2. Professional ASP.Net 2.0/3.5/4.5 (from wrox publications)
  3. C# 4.0 – The Complete Reference By Herbert Schildt

Online Tutorials & Trainings for ASP.Net:
               For ASP.Net technology, there are so many good online tutorial sites available. Some of them for your reference:
www.asp.net/getstarted
http://www.codeproject.com/KB/aspnet/
http://channel9.msdn.com/Tags/asp.net

What do you think?
                  The above are my professional experience, that I have earned over lot of time. Do you want to say something, please let me know thru comments.

Wednesday, April 16, 2014

Daily Interview Question #8 : What are the efficient ways to show million records in a page?

By Francis   Posted at   1:27 PM   No comments

The below answer is my own suggestions that I gave as an answer.

                  In practical there is no need of pull million of records at one call. Instead of that we can show 10 or 100 of records in the web page with pagination. To pull the records from Database, just write a stored procedure it will also contains the pagination logic. That is, if the second page clicked, the stored procedure pull the rows from 101 to 200.

The above method consist 2 advantage:

1) Increased performance (only we pull and show 100 records).

2) Faster retrieval.

Monday, April 14, 2014

JQuery Tips and Tricks #1–Simple Addition using JQuery

By Francis   Posted at   5:51 AM   JQuery Tips No comments
                                In this post we are going to see a simple addition of 2 numbers using JQuery. Copy and paste the below code:

Sunday, April 13, 2014

ASP.Net Forums – FAQ #1 : How to enable Adsense in my site?

By Francis   Posted at   8:14 PM   Enable Adsense 1 comment
                        


This is the most frequently asked question in ASP.Net Forums. As a Adsense user (struggled with google over 6 months I got my adsense approval), I’m going to explain how to enable adsense in your website regardless of technology (either you used ASP.Net or PHP or Java etc) which you are using to built your site.

I just want to tell one thing first there is no short cut to get your adsense approval from google. Go with the below guidelines:

Sunday, March 16, 2014

Daily Interview Question #7: Implicit and Explicit Implementation of Interface

By Francis   Posted at   12:22 AM   OOPS interview Questions No comments

                                                   This is the most common interview question for experienced professionals.

Normally an interface can be implemented in a class in a normal way which is a implicit implementation. Sometime, we may have same method name in different interfaces. If this is the case, we need to do explicit implementation of the interface method. The main use of explicit implementation is to avoid the ambiguities between the class or method name. In order,  to do that the interface name put before that interface’s method.

 

Below example, shows the implicit and explicit implementation:

 

namespace ConsoleApplicationC
{
    // 2 interfaces with same method name
    interface IintegerAdd
    {
        void Add();
    }
    interface IfloatAdd
    {
        void Add();
        void Multiply();
    }


    // We implement Both interfaces
    class ArithmeticOperation : IintegerAdd, IfloatAdd
    {
        // Implicit  Implementation : There is no name collision so we can implement implicitly
        // NOTE : public modifier MUST here
        public void Multiply()
        {
            float a = 1.5f, b = 2.5f;
            Console.WriteLine("Float Multiplication is:" + a * b);
        }


        // Explicit Implementation :  Explicitly tell the compiler that we implement the interface IintegerAdd
        void IintegerAdd.Add()
        {
            int a = 10, b = 20;
            Console.WriteLine("Integer Addition Is:" + (a + b));
        }


        // Explicit Implementation :  Explicitly tell the compiler that we implement the interface IfloatAdd
        void IfloatAdd.Add()
        {
            float a = 1.5f, b = 2.5f;
            Console.WriteLine("Float Addition Is:" + (a + b));
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            ArithmeticOperation objA = new ArithmeticOperation();
            IintegerAdd iobj = (IintegerAdd)objA;
            iobj.Add();
            IfloatAdd fobj = (IfloatAdd)objA;
            fobj.Add();
            Console.ReadKey();
        }
    }
}


Output :


 


Integer Addition Is:30
Float Addition Is:4

Tuesday, March 11, 2014

Visual Studio Tips & Tricks - 8: Breakpoint will not currently be hit. No symbols have been loaded for this project.

By Francis   Posted at   5:50 PM   Visual Studio Tips and Tricks 2 comments

Most of the developers who are using Visual studio have encountered the above problem. As a ASP.Net Developer I have this atleast once a day. So the below are my tricks to get ride of this issue.

 

1) Just Close the VS IDE.

2) Go to Task Manager and kill the worker process. (If you are working on  ASP.Net application).

3) Go to the .Net installation folder ( Normally it should be C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files OR C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files) and clear the temp files from the temporary folder.

4) Open the solution and "Rebuild" entire solution. Now try to attach the debugger.

 

Please note that, in some machines you may have 2 framework installation, one for 32-bit and another for 64-bit. So when you go with step 3, pay close attention and make sure which .net framework was used and also which version no (either 2,3,3.5 or 4) was used by your application.

 

Hope this helps!

Saturday, March 8, 2014

Using MSCaptcha

By Francis   Posted at   9:08 PM   MSCaptcha No comments

                                    Recently, in one of my project I need a captcha for my application. Just a google search provides number of options. I need a open source solution, so I go with krisanov’s solution. I just download and try to using that on my project. However it doesn’t works fine. Just follow the instruction mention by mudasar in this url. But I have encountered several problems (that is it doesn’t display any captcha image) the when I added that into my project, which leads to write this post.

Below are the steps that I have followed:

 

1) Just download the captcha from the url.

2) Add the reference into the project by “Right Click on the Project –> Add Reference”.

3) After that you need to include the below lines into web.config file:

 

<system.web>
    <httpHandlers>
        <add verb="GET" path="CaptchaImage.aspx" type="WebControlCaptcha.CaptchaImageHandler, WebControlCaptcha"/>
    </httpHandlers>

</system.web>
<location path="CaptchaImage.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

 

What previously done, I have missed out entire “location” element, which is also not mentioned in the mudasar’s tutorial. I have found this solution in this asp.net forum thread.


Hope this helps to someone!

Wednesday, March 5, 2014

VisualStudio Tips & Tricks - 7 : Using Transact-SQL Editor in Visual Studio 2010

By Francis   Posted at   10:13 AM   Visual Studio Tips and Tricks No comments
                           Few months ago, when we upgrade from VSS to TFS, somehow we lost intellisense in SQLServer Management studio 2008 R2. We struggle a lot to obtain. But no luck till now. However, currently we are using Visual Studio 2010, which enriched with lot of futures.
            Instead of using SQL Server Management, what I did was open the SQL file using Visual Studio 2010. In Visual Studio, Right click on the Menu bar, from the floating menu “check” the “Transact-SQL Editor”.

image
Now we got the toolbar available in SQL to do some basic operations like connect the SQL Server, Execute the Transact SQL etc., The main benefit in this approach is the intellisense works fine with in the “Transact-SQL Editor”. So my problem solved temporary.
One of the main attraction in this feature is, we can do all basic operations with in this editor. However, I’m not at all a DBA, just a developer who used SQL server as a backend. This is more convenient way work as of now.

Hope this may help to some one!!

Tuesday, March 4, 2014

Visual Studio Tips & Tricks – 6 : Multi-Copy functionality in Visual Studio

By Francis   Posted at   12:26 PM   Visual Studio Tips and Tricks No comments

                                    Some time we may need to copy the multiple code snippets (that is we may need to copy and paste lines that are not in order) in a file and paste it in another location of the file inside Visual Studio. For example, we have 5 lines of text, what we need is to copy the 1,3 and 5 line of text and paste it on some other location. To achieve that functionality to do the following:

 

1) Copy the code snippets using Ctrl+C key combination. (That is select the line 1 and press Ctrl + C and select line 3 press Ctrl + C and so on).

2) When you paste that code press the key combination Ctrl + V + Shift key, which rotates the copied lines of text. To paste a particular selected text just press Ctrl + V.

 

Hope this helps to some one!

Tuesday, February 4, 2014

Daily Interview Question #6: What are the different types of Constructor in C#?

By Francis   Posted at   1:03 PM   C# Interview Questions No comments

Below is the list of Constructors available in C#:

1. Default Constructor

2. Parameterized constructor

3. Static Constructor.

 

By default constructor have “public” as access specifier. A class can have more than one Constructor. In C# “this” keyword is used to access the constructor from another constructor. By default, C# will provide a default constructor if no constructor declared.

 

Hope this helps!

Monday, February 3, 2014

Attach Javascript to Button

By Francis   Posted at   2:01 PM   No comments

In this tutorial I’m going to explain how to add a javascript snippet to the ASP.Net server side Button Control.

 

Code:

Copy the below code in an .aspx file:

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:Button runat="server" ID="btnSubmit" Text="Click Me" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>


 


Copy the below code in an .aspx.vb file:

 
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btnSubmit.Attributes.Add("onclick", "alert('Button Clicked');return false;")
End Sub


Explanation:


The above code add “onclick” attribute to the Server side button “btnSubmit”. The attribute value is just a javascript snippet, which just show an alert box.


 


Take a look, after the alert we specify the “return  false;” which avoid the webform to be refreshed.


 


Hope this helps!

Tuesday, January 28, 2014

Daily Interview Question #5 : What is the difference between “Method Overloading” and “Method Overriding”?

By Francis   Posted at   1:47 PM   OOPS interview Questions No comments

Method overloading

Method overriding

method overloading used to achieve “early binding” or “static binding”. method overriding used to achieve “late (dynamic) binding” or “runtime polymorphism”.
method overloading means, in a class method can be declared with same method name and with different parameters. method overriding means, a method defined in base class can be redefined in the derived classes.
method signature (method name + parameter) must be different in method overloading. method signature must be same in method override.

 

Sample Program:

using system;
using system.collections.generic;
using system.text;

namespace consoleapplicationc
{
//Base class
class baseclass
{
private int add(int a, int b)
{
return a + b;
}
// Overload the Above Method
private float add(float a, float b)
{
return a + b;
}
// virtual method - Indicates this will be override in Child class
public virtual string whereiam()
{
return "In Base Class";
}
}
// Derived Class
class derived : baseclass
{
// Base class Method Override here
public override string whereiam()
{
return "In Derived Class";
}
}
class program
{
static void main(string[] args)
{
// Just create base class reference
baseclass basereference;
// Create Base class Object
baseclass baseobj = new baseclass();
// create object for Derived class
derived derivedobj = new derived();
// Base class reference contains derived object
basereference = derivedobj;
// Now Derived class method called with base ref
string strvalue = basereference.whereiam();
console.writeline(strvalue);
// Now Base class ref contains base object
basereference = baseobj;
string strval = basereference.whereiam();
console.writeline(strval);
console.read();
}
}
}
Output:
in derived class
in base class

Monday, January 27, 2014

Daily Interview Questions #4: What is the difference between Abstract Method and Virtual Method?

By Francis   Posted at   1:29 PM   OOPS interview Questions No comments

Abstract Method:

Abstract method specified by “abstract” keyword.

An abstract method contains no definition. Derived class must implement the abstract methods.

Object cannot be created for abstract class. That is abstract class can not be instantiated.

Virtual Method:

Virtual method specified by “virtual” keyword.

Used to implement “Run-Time” polymorphism.

Derived classes not forced to implement the “Virtual” methods that is available in Base class.

The process of redefine the virtual method in a derived class called as “Method Overridding”.

Friday, January 24, 2014

Daily Interview Question #3: What are the MEPs available in WCF?

By Francis   Posted at   11:12 PM   ASP.Net Interview Questions No comments
              MEP is the short form for Message Exchange Pattern. In Windows communication foundation, 3 types of Message exchange patterns are allowed. They are:

Thursday, January 23, 2014

Daily Interview Question#2 : What are the events will be fired when the “gridview.DataBind()” method called?

By Francis   Posted at   11:34 AM   ASP.Net Interview Questions No comments

When the Gridview.DataBind() method called, below events are fired in the following order:

  1. Databinding
  2. RowCreated  (Called for Each row)
  3. RowDatabound (called for each row)
  4. DataBound

Wednesday, January 22, 2014

Daily Interview Question #1 : What is Abstract Class?

By Francis   Posted at   10:49 AM   ASP.Net Interview Questions No comments

 

An abstract class is like a class with some future. That is:

i. It contains at least one or more abstract method(s).

ii. It will always act as a base class.

iii. It cannot be instantiated. That is not possible to create instance for that class.

Grid View : Binding Dropdown inside a Gridview

By Francis   Posted at   9:15 AM   Gridview Sample No comments
In this gridview tutorial, I’m going to explain how to bind a drop down list with in a gridview. The drop down list located inside gridview in a “Template” Column. Paste the below code in an aspx page.

Connect with Us