Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools



Thursday, August 30, 2012

DataReader example in Asp.Net

- No comments
In this article we will discuss about asp.net datareader and we will see one example of that. You can also check my laster article on difference between datareader and dataset in asp.net.

DataReader:
- It works in connected architecture mode, so it needs an active connection. You can check my last article on Connected and Disconnected Architecture Ado.Net.

- It supports forward only and read only access.

- Performance is better in case of data access using datareader.

Tuesday, August 28, 2012

Adding Custom Event Receivers to a List

- No comments
You can add Custom Event Receivers to a List in SharePoint 2010 using Windows PowerShell. Event Receivers can be used to execute code before or after an Item is created, updated, or deleted. It’s possible to run the code either Synchronous or Asynchronous. The example below demonstrates how you can add a Custom Event Receiver to a List in SharePoint 2010:

PS > $spWeb = Get-SPWeb http://siteurl

asp.net updatepanel refresh page

- No comments
In this article we will discuss how we can refresh a page from a button click inside a updatepanel. Also you can check my last article on Ajax Progress bar in Asp.Net.

As I have explained in my last article on Ajax updatepanel example in asp.net, button click will not do postback. Suppose there are 2 buttons, in 1 button I want to do postback, remember since the button is inside the UpdatePanel so it will not do postback. We can do postback by using asp:PostBackTrigger control.

Monday, August 27, 2012

Ajax updatepanel example in asp.net

- No comments
In this article we will discuss about how to use updatepanel in asp.net. Also you can check  my last article on Ajax Progress bar in Asp.Net. Also you can see some Ado.Net and SharePoint 2010 articles.

Normally we use updatepanel for partial page refreshing, means the code within that panel will not postback. Microsoft provides AJAX which helps us in doing so.

For this our .aspx page should contain one ScriptManager and can contain more than one updatepanel control. The code that we put inside the updatepanel will not do postback on click event. UpdatePanel and

Saturday, August 25, 2012

Show hide div using jQuery in asp.net

- No comments
In this article we will discuss about how we can show or hide a div using jQuery in our asp.net application. You can also check my other article on jQuery on how to disable right click by using jQuery.

First we have to give reference to the jQuery library like below:

<
script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

Then we need to write the function. Below is the full .aspx code.

Friday, August 24, 2012

Disable right click by using jQuery in asp.net

- No comments
In this article we will discuss how we can disable right click using jQuery. You can also check my laste article on how to open hyperlink in new tab window using jQuery here.

In most of the pages sometime we required to disable right click option. We can do it easiy using jQuery. Below is the code:

Thursday, August 23, 2012

Immediate Opening for .Net Sr.Engineer in Honeywell Technologies

- No comments
Here is the Job description for Immediate Opening for .Net Sr.Engineer in Honeywell Technologies, Bangalore
Job Description:
  • 4-5 yrs experience with .Net 3.5 and above
  • Should have MVP Framework patterns
  • Must have skills WCF and WWF

Tuesday, August 21, 2012

Ado.Net Data access using disconnected architure in Asp.Net

- No comments
In this article we will dicuss about how we can acess Ado.Net data using disconnected architure. You can also check my last article on DataSet and DataReader in asp.net here.

We need to use DataAdapter to work with Ado.Net in disconnected enviroment.

string connectionString = "Your connection string goes here";

//If the connection string is in web.config file then we can write below:

string connectionString = ConfigurationSettings.AppSettings["ConnectionString"].ToString();

SqlConnection con = new SqlConnection(connectionString);

SqlDataAdapter da = new SqlDataAdapter("SELECT * From Customers",con);

DataSet ds = new DataSet();

da.Fill(ds,"Customers");

Gridview1.DataSource = ds;

Gridview1.DataBind();

If you want to convert the dataset to data table then we can assign like below:

DataTable dt = ds.Tables["Customers"];

You can also check some javascript and jQuery articles.

Sunday, August 19, 2012

First Asp.Net MVC 4 application

- No comments
In this article we will discuss about our first demo asp.net mvc 4 application. This will include the steps to create asp.net mvc 4 application as well as the default project structure.

After you installed asp.net mvc 4, Open Visual Studio 2010 then go to File -> New -> Project.

This will open the New Project dialog box, from there select ASP.NET MVC 4 Web Application and give a name and set the location and click on OK as shown in the figure below. Remember the Target framework should be selected as .Net Framework 4.

Saturday, August 18, 2012

How to Install Asp.Net MVC 4?

- No comments
In this article we will discuss about how to install Asp.Net MVC 4 in development machine.

MVC 2 comes in built with Visual Studio 2010, But if we want to work on MVC 3 or MVC 4 then we have to install it separately.

Microsoft provides Web Platform Installer is a small tool that provides a quick way to install the various components of the Microsoft web platform onto your development PC, including IIS Express, SQL Server Express, SQL Server Compact, MVC, and Visual Web Developer Express.

If you already have Visual Studio 2010 on your PC, this package will also install Service Pack 1 for Visual Studio 2010, but if you don’t have Visual Studio, the free Visual Web Developer 2010 Express will be installed.

To install Asp.Net MVC 4 click on the below URL

http://www.asp.net/mvc/mvc4
It will allow the file to save, save the file in hard disk.

Then click on setup file like below:


Then it will download the web installer as shown in the figure below:

Then click on Install as shown in the figure below:

Then click on accept as shown in the figure below:
Then it will install Asp.Net MVC 4.

Friday, August 17, 2012

Introduction to Asp.Net MVC

- No comments
- ASP.NET MVC is a web development framework on the Microsoft .NET platform that provides a way for developers to build well-structured web applications.

- ASP.NET MVC provides an alternative to Web Forms for building web applications on the .NET platform.

- This was first come in 2007 and Latest version is ASP.NET MVC 4

- MVC stands for Model-View-Controller.

- The ASP.NET MVC framework is very lightweight, testable and presentation framework.

- Asp.Net mvc helps of building an application that provides a loose coupling between input logic layer, business logic and UI logic.

- The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application.
- You can separately develop each part with much dependancy on other layers.

- It provides better support for test-driven development



- Model: The model consists of application data and business rules. (Data Access Layer)

- Views: This is the user interface. UI usually created from the Model data. (Presentation Layer)

- Controllers:  This ususally connects the model and the view. (Business Logic Layer)
- Asp.Net MVC framework provides a powerful URL-mapping component that lets you build applications that have comprehensible and searchable URLs. URLs do not have to include file-name extensions, and are designed to support URL naming patterns that work well for search engine optimization (SEO) and representational state transfer (REST) addressing.

- It does not use View state or postbacks etc.

- Official web site http://www.asp.net/mvc

.Net Openings with Societe Generale

- 1 comment
Position 1 - Dotnet SSE
Strong .Net developer, 4-7 years experience - Very good fundamentals on Dot net, Threading, LINQ. Exposure to Silverlight is good
(Silverlight exposure is must though not at expert level). Background in banking domain is desired

Position 2 - Dotnet SSE
* Clear understanding of Software Development life cycle and process Oriented
* Need 3-6 year experience in C#, ASP.NET, WCF or Web Services
* Good theoretical knowledge of Silverlight 3.0 or above OR at least 6 month work experience in Silverlight
* Candidate should have work experience in either ASP.net or Silverlight

Thursday, August 16, 2012

What is Anonymous Types in C#.Net ?

- No comments
In this article we will discuss about What is Anonymous types in C#.Net. Also you can check an article on Strings and StringBuilder in C# here.

- This comes with C#.Net 3.0

- Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first.

- Mostly used in LINQ Query Expressions.

- Anonymous types are class types that derive directly from object, and that cannot be cast to any type except object.

- Anonymous types are immutable.

- We can define the anonymous types with Var keyword like below:

var name = "SharePointDotNet Anonymous type";

Then internally it will convert to:

string name = "SharePointDotNet Anonymous type";

- There are certain rules to declare Anonymous types:

1. Anonymous types must always have an initial assignment and it can’t be null.



2. Anonymous types can be used with simple or complex types.

3. Anonymous types support IntelliSense.

4. Anonymous types cannot be used for a class field.

5. Anonymous types can be used as initializers in for loops.

6. Anonymous types can be used with arrays.

7. Anonymous types are all derived from the Object type.

8. Anonymous types can be returned from methods but must be cast to object.

Complex Anonymous Types examples:
var details = new {Name = "SharePointDotNet", Age = 5};

Internally it will convert to:

 private string name;
   private int age;

   public string Name
   {
      get { return name; }
      set { name = value; }
   }

   public int Age
   {
      get { return age; }
      set { age = value; }
   }

Wednesday, August 15, 2012

Uploading documents to document library in SharePoint 2013

- No comments
In this video tutorial we will see how to upload documents to document library in SharePoint 2013. This tutorial is from Asif Rehmani which is the owner of SharePoint-Videos.com. Also you can check some video tutorials on SharePoint 2013 Team Site Overview and SharePoint 2013 Search Video Tutorial.

Also you can check what is the difference between list and document library here and how to create a document library in SharePoint 2010 here.

Below is the video tutorial:

Open hyperlink in new tab using jquery

- No comments
In this article we will discuss how to open a hyperlink in new window or tab using jQuery or JavaScript. You can also check my last article on jQuery sample here. Also you can see some SharePoint articles, Jobs.

The javascript code to open hyperlink in new tab is below:

 <script type="text/javascript">
        $(function () {
            $("a").attr("target", "_blank");
        });
    </script>

This will open every links in a page in new window. But suppose you want it for a particular section then follow below code:
jQuery approach:

Add .js file to page as like below:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

Then write the script code like below:
<script type="text/javascript">
       $('.divclassname a').live('mouseover', function () {
           $(this).attr('target', '_blank');
       });
    </script>

<div class="divclassname">
<a href="http://www.sharepointdotnet.com" > SharePointDotNet</a>
</div>
<a href="http://www.fewlines4biju.com" > Fewlines4Biju</a>

Here in the above schenerious, only SharePointDotNet link will open in new tab or window but Fewlines4Biju will not open in new tab. Because we have mention the div class name in the jQuery function.

Tuesday, August 14, 2012

Job Opening with Asp.Net and MVC

- No comments
Hi, we have opening with our client, Bangalore
Experience: 3.5 to 5 yrs

Mandatory Skills:
- Must have worked on .Net framework 3.5/4.0

- Must have worked on C# and ASP.net

Monday, August 13, 2012

Openings for Dot net Developers

- No comments
Greetings from Marlabs Software (P) Ltd
We have an immediate opening with one of our Business Partner for following position,.

Position: Dot Net Developer
Experience: 4 to 6 Yrs
JobLocation: Bangalore

Saturday, August 11, 2012

Asp.Net User Control

- No comments
In this article we will discuss about what is an user control and how to create an use user control in asp.net. Also you can check my last article on Access Master Page controls from the Content Page in Asp.Net here and you can see some SharePoint 2013 articles and SharePoint 2010 articles.

- A user control is a reusable control in asp.net. we can make a single user control and can reuse that in different pages.

- User control extension is .ascx

- We can write HTML code as well as we can write code file in .cs file.

- The code file is inherited from System.Web.UI.UserControl.

- User controls can not be directly requested, they must be embedded with a .aspx page.

It is very easy to create an user control in Visual Studio 2010.

To add one use control Right click on the project -> Add new item and from the Add New Item dialog box select Web user control and give name and click on Add as shown in the figure below:

This will create the user control.
By default the html code will appear.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestUserControl.ascx.cs" Inherits="TestUserControl" %>

Then we will put one label where we will print something.

So the HTML code will be:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestUserControl.ascx.cs" Inherits="TestUserControl" %>

<asp:Label ID="lblWelcome" runat="server" Text=""></asp:Label>

And .CS code:



protected void Page_Load(object sender, EventArgs e)
    {
        lblWelcome.Text = "Hello World of User Control !!!";
    }
This step finishes our creation user control part. In the next step we will see how to call this user control in .aspx page.

1st Approach:

For this we have to add through Register attribute and we need to give tagname, tagprefix and source name like below:

<%@ Register src="TestUserControl.ascx" tagname="TestUserControl" tagprefix="uc1" %>

Then we need to call like below:
<uc1:TestUserControl ID="TestUserControl1" runat="server" />

where uc1 in the tagprefix and TestUserControl is the tag name.

2nd Approach:

This is the simplest approach, Just drag and drop the user control to the page where you want to the design view.

Friday, August 10, 2012

Check if string contains a particular string in C#.Net

- No comments
In this article we will discuss if a particular string is present inside a string in C#.Net. You can also check my last article on Extract first N words from a string with C#.

Suppose a string contains different strings separated by " | " character. From there we will find one particular string whether it exists or not.

Below is the code to check.
First we have to convert the string to string array with the string separator and then we will check  whether  the string is exists or not in the string array.

Full code:
 void CheckString()
    {
        string fullString = "SharePointDotNet|EnjoySharePoint|Fewlines4Biju";
     
        string searchString = "SharePointDotNet";
     
        char[] separator = new char[] { '|' };
     
        string[] s1 = fullString.ToLower().Trim().Split(separator);

        if (s1.Contains(searchString.ToLower().Trim()))
        {
            //The string is present !
        }
        else
        {
            //The string is not present !
        }
    }
You can also check an article on Remove HTML tags from string in C#.

Thursday, August 9, 2012

HCL Is Hiring .Net developers

- No comments
HCL Technologies is hiring for.Net. Please find the JD below

Experience : 6-8Yrs
Location : Bangalore
Educational Qualification : - BE/B-TECH/ME/MTECH/MCA/MSC/BSC

Note : Due to project criticality we are looking immediate joiners/15 Days of notice period.

Job Description:

Wednesday, August 8, 2012

Session state in Asp.Net

- No comments
In this article we will discuss about session state state management technique. You can also check View State, Query String and Cookies.

Through cookies or query string it is very difficult to store and access complex information like custom data objects. Session allows you to store any type of data in memory on the server. The information is protected, because it is never transmitted to the client. Every client that accesses the application has a different session.

Query String in Asp.Net

- No comments
In this article we will discuss about another state management technique query string in asp.net. You can also check my last article on Cross page posting in Asp.Net here.

Query String is one of the useful technique in Asp.Net to transfer values from one page to another page.

Syntax:
Response.Redirect("~/SecondPage.aspx?ID=1");

You can also pass multiple parameters like below:

Response.Redirect("~/SecondPage.aspx?ID=1&Name=SharePointDotNet");

To retrieve the values like below:

int intID=Convert.ToInt32 (Request.QueryString["ID"]);

string strName= Request.QueryString["Name"].ToString();

This is one of the simplest technique. The advantage of query string is that it’s lightweight and doesn’t exert any kind of burden on the server. But there are some limitations also.


Limitations:
- The information should be simple string and should contain legal characters.

- Information is clearly visible to the user, so it not recommended for sensitive information.

- The amount of data depends upon the brower url length capabilities which is 1kb or 2kb.

Since the URL is visible to users we can encode that like below:

Response.Redirect("~/SecondPage.aspx?ID=Server.UrlEncode(1)");

And to decode the value we have to use UrlDecode value:

int intID=Convert.ToInt32 (Server.UrlDecode((Request.QueryString["ID"])));

Monday, August 6, 2012

Cross page posting Asp.Net

- No comments
In this article we will discuss about cross page posting in Asp.Net Also you can check my last article on Advantages and disadvantages of asp.net cookies.

Cross page posting is a very useful technique for transforing information between pages. This is a very simple technique. This is available to those control which implements IButtonControl interface like Button, imagebutton, LinkButton etc. It depends on PostBackUrl url property of the controls.

<asp:LinkButton runat="server" ID="lnkButton" PostBackUrl="2ndPage.aspx" Text="Go to 2nd Page" />

Here is the example:

First Page HTML Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FirstPage.aspx.cs" Inherits="FirstPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>First Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/SecondPage.aspx">Go to 2nd Page</asp:LinkButton>
    </div>
    </form>
</body>
</html>
Here in the link button we have given the PostBackUrl.

Now in the second page we will retrieve the value as below:

Second page .cs code:

protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            lblStatus.Text = "Your last page title: " + PreviousPage.Title;
        }
    }

Here in the label it will show the previous page title.

Sunday, August 5, 2012

Regular Expressions validation control Asp.Net

- No comments
In this article we will disucss about Regular Expressions validation control which is very much useful to validate email address, phone number etc. You can also check about Validation controls in Asp.net here.

Regular expression will be helpful to validate email id, phone number, zip code etc. In this example we will validate an email address for a textbox.

HTML Code:
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
        <br />
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ControlToValidate="txtEmail" ErrorMessage="Please enter a valid email id"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

Here the main properties are:
ControlToValidate - This is id of the control which we will validate, here the textbox of Id- txtEmail.

Error Message: This is the error message that will appear to user if invalid data enters.

Validation express: This is the validation expression, here is to validate email address:
"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

So need to write validation expression for different conditions like:
Password validation that will be menimum 4 characters but not greater than 20 characters: "\w{4,10}"

Saturday, August 4, 2012

Write exception to Event Log in Asp.Net C#.Net

- No comments
In this article we will discuss how to write exception to Event Log in Asp.Net.  You can check my last article on Exception Class in Asp.Net C#.Net

Event log will be accessible from Start -> Run -> eventvwr. To write the exception message in the Event log is now easy in .Net by use of the namespace System.Diagnostics;

Below is the code to write to event log:

using System.Diagnostics;

try
{
// Code
}
catch (System.Exception ex)
{
EventLog log = new EventLog();
log.Source = "Comes from .Net Application";
log.WriteEntry(ex.Message, EventLogEntryType.Error);

}
finally
{
// Clean up block.
}

Here in the above code the exception message will be written in the event log with source as "Comes from .Net Application".

Now open the event viewer window ( Start -> Run -> eventvwr ) and Navigate to Windows Logs -> Application , You will able to see the error message.

Friday, August 3, 2012

ViewState example Asp.Net

- No comments
In this article we will discuss about view state which is a popular statemanagement technique. Also you can check an article on Difference between cookie and session in asp.net.

View state is a common technique to store information that’s used for multiple postbacks in a single web page. View state uses a hidden field that ASP.NET automatically inserts in the final, rendered HTML of a web page.

Syntax:
To store values in viewstate:

ViewState["Counter"] = 1;

To retrieve values from view state:

Int viewstateValue = (int)this.ViewState["Counter"];

But it is always good to check wether the view state value is null before trying to retrieve it like below:

if (ViewState["Counter"] == null)
{
//Handle the null value
}
else
{
viewstateValue = (int)ViewState["Counter"] + 1;
}

if you will not check for null, then if the view state contains null, it will through an null reference exception.

View state value is readable and is a converted Base64 string which can be tampered. But we can encrypt that in page level as well as project level.

To encrypt in Page level we have to add ViewStateEncryptionMode="Always" in Page directive.

Also we can made changes in web.config like below:

<pages viewStateEncryptionMode="Always" />
</system.web>
</configuration>

Also apart from integer or string types we can store our custom objects. But the custom object should be serializable.

Here is an example:
[Serializable]
public class Customer
{
private string firstName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}

public Customer(string firstName, string lastName)
{
FirstName = firstName;
}
}

Customer customer = new Customer("SharePointDotNet");
ViewState["CustomerDetails"] = customer ;

To retrive the custom object :
// Retrieve a customer from view state.
Customer customerRetrive = (Customer)ViewState["CustomerDetails"];

Typecast is very much necessary.

You can also check some SQL Server articles like: Joins in SQL Server 2008 and Delete and Truncate in sql server 2008 .

Thursday, August 2, 2012

Exception Class in Asp.Net C#.Net

- No comments
It is always good to do exception and error handling in Asp.Net or C#.Net code. Because it is not good idea to show exception message rather we should catch the proper exception and show proper messages to users. .Net language supports structured exception handling. Whenever an error occurred .Net framework creates an exception object which we can use to do exception handling.

Microsoft .Net framework provides The Exception class known as System.Exception. This is the base class for all exceptions. Means every exception is derived from this base class. Some of the classes provided by DotNet framework are NullReferenceException, IOException, SqlException, DivideByZeroException, ArithmeticException, IOException, SecurityException etc.

The exception has some useful members/properties to know more about the error like InnerException, Message, StackTrace, Source etc. We can get these like below:

catch (System.Exception ex)
{
string errorMessage = ex.Message;
}

try
{
// Code
}
catch (System.Exception ex)
{
// Error catch block
}
finally
{
// Clean up block.
}

We can write the generic Exception class. But its is better to trap proper exception message. We can trap by using multiple catch block like below.

try
{
// Risky database code goes here.
}
catch (System.Data.SqlClient.SqlException ex)
{
string errorMessage = ex.Message;
// Catch SQL Exception
}
catch (System.NullReferenceException ex)
{
string errorMessage = ex.Message;
// Catches null reference exception.
}
catch (System.Exception ex)
{
string errorMessage = ex.Message;
// Error catch block
}

If the particular exception belongs to SqlException then it will go to the 1st exception block, else if it belongs to nullreference exception then it will go to the 2nd catch block else it will go to the 3rd catch block since it is the generic exception block.

You can also write nested try catch and exception code.

Wednesday, August 1, 2012

Null Coalescing Operator in C#.Net

- No comments
In this article we will discuss about C#.Net Null Coalescing operator. You can also check some more C#.Net articles here.

This is a binary operator which is helpful incase of Null values evaluation and is noted as ??

Syntax:
A ?? B

Here it means if A is not null then evaluate A else take the value of Y.

Example:

int? i = null;
int j = a.Value;

Here in the 2nd statement it will give an exception because we are trung to get the value which is null.
So to avoid the situation we can use Null Coalescing Operator

int? i = null;
int j = a ?? 0;

Here it will not give any exception rather it will take 0 and assign it to j.

If a is not null then it will evaluate a else it will take the value provided in Null Coalescing Operator whcih is 0 in this example.