Banner Ad

Sunday, July 9, 2017

How to Start My Final Year Project in .Net?

By Francis   Posted at   11:47 AM   ASP.NET Books 2 comments
                      

Most of the college students who are doing their final year projects (especially computer science students) and beginners are asked about the below questions:
  • How to start an ASP.Net Projects?
  • What are the basic Software I need to code .Net?
  • What are the books I referred to become better programmer?
In this post I just want to guide those people by providing some basic tips.


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. 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 an easy to move, way in ASP.Net. The above lists are specific to .Net.

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.
In the meantime, Microsoft also introduced Visual Studio Community Edition, which is a complete set of IDE. So instead of going with Express Edition, you can try it. You can start download it from here.
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.

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.c-sharpcorner.com/1/224/Asp-Net-programming.aspx
http://www.codeproject.com/KB/aspnet/
http://channel9.msdn.com/Tags/asp.net

What do you think?
                   The above are my personal experience. Did i miss anything or do you want to say something, please let me know you thoughts as comments.

Wednesday, October 12, 2016

ASP.Net MVC : TempData - A Closer Look

By Francis   Posted at   1:43 PM   TempData and ASP.Net MVC 1 comment
             
               

                As an ASP.Net MVC developer, you may frequently involved with these terms like Tempdata, viewdata and viewbag. In this post, I’m going to take a close look about TempData and how it works.

Read: ViewBag, ViewData and TempData

For explanation purpose, I’m going to create a small MVC project with 3 views and a controller.
  1. Index.cshtml – This is the default view, which is loaded by the default action method.
  2. Page1.cshtml
  3. Page2.cshtml
And the controller named as:
  1. DefaultController.cs 
TempData:

We will start with TempData. I will set the value of TempData in the Action method “Index”, like below:

using System.Web.Mvc;
namespace SessionHandlingInMVC.Controllers 
{ 
    public class 
DefaultController : Controller 
    { 
        // GET: Default         
public ActionResult Index() 
        {             
          TempData["MyTempDataValue"] = "Value initialized in Index Action Method"; 
          return View(); 
        } 
        
public ActionResult Page1() 
        { 
            return View("Page1"); 
        }
public ActionResult Page2() 
        { 
      return View("Page2"); 
        } 
    } 
}

In the “Index” view, we can get the value of the initialized “Tempdata” value as below:

<h2>Index Page</h2>
<p> 
   @{ 
       string strTempDataValue = 
(string)TempData["MyTempDataValue"]; 
    } 
    @strTempDataValue 
</p>

Please take a close look how the value is retrieved from the “TempData”.You can’t directly assigned to it the specific type.  A typecasting is needed, when you retrieved the value from Tempdata. The above snippet just get the value from TempData dictionary and print it on.

In the next snippet, I’m going to change the above snippet a little bit like below:

<h2>Index Page</h2> 
<p> 
   @{ 
       string 
strTempDataValue = (string)TempData["MyTempDataValue"]; 
    } 
@strTempDataValue
    @{ 
        string strAnotherRead = 
(string)TempData["MyTempDataValue"]; 
    } 
    @strAnotherRead 
</p>



In the above snippet, we have read the TempData value as twice. As a result the value also printed twice in the view.


The above result confirm that, you can read the TempData value inside the current request as much time as possible.

In the following snippet, I’m going to read the value of the TempData in the next view, which is rendered by the action method “Page1”.

<h2>Page1</h2> 
<p> 
    @{ 
        string 
strTempDataValueInPage1 = (string)TempData["MyTempDataValue"]; 
    } 
    
@strTempDataValueInPage1 
</p>
 

In order to test the above scenario, first you must render the view “Index” (since in that action method alone the tempdata value is initialized) and then you call the “Page1” view. As you can see that, TempData value is not available in the next request.

Wait! The conclusion is not yet over. I want to try some thing more. That is, as per the above codes:

1. First I render the “Index” page, where the Tempdata value is read and print it.
2. After I call the action method “Page1”.

What will happens if I didn’t read the value of Tempdata in “Index.cshtml” view and try to read the “Page1.cshtml” view. In order to test, I made the below changes in Index view.

Index.cshtml:
<h2>Index Page</h2> 
<p> 
    No Temp Data read here 
in Index.cshtml 
</p>


Page1.cshtml:

<h2>Page1</h2> 
<p> 
    @{ 
        string 
strTempDataValueInPage1 = (string)TempData["MyTempDataValue"]; 
    } 
    
@strTempDataValueInPage1 
</p>


Now, you got the value in the value of Tempdata in the next request. That means, your first request render the “Index” page, and the next request render the “Page1”.

If you refresh the above page, you will get the result as below: that is, the Tempdata is unavailable once it read. So you get the Tempdata value as empty.

So the conclusion is : After Tempdata value is initialized and it’s not yet read in the current request, then it will be available in the next request. Once it is read, it will not available.

Few words about Keep() and Peek() method:

After you read the tempdata, if you call the keep method, it will marks the all tempdata keys or specific key for retention.

If you want to fetch the key and mark the key for retention (keep the key for the next request) then you can go with Peek method.

Connection between Session and Tempdata:

Yes, Tempdata uses “Session” object in the backend. That is, whenever you use a tempdata it will handled by session. But the main difference is, the Tempdata will be removed (by default) after the first read.

At the same time, you may have the doubt, that either tempdata is specific to the user as like as “Session”? The answer is Yes. Since the Tempdata, is backed up with Session, Tempdata is also specific to user, like Session object.

Also, the another question is, since the Tempdata backed up with Session, what will happened if we go with same key for session and Tempdata as like below:

The answer is it won’t colloid. It will considered as a different one and it will serve its own purpose as per the convention.

In summary:
  1. TempData store the value using key.
  2. TempData backed up with Session.
  3. Need type casting when the stored value retrieved.
  4. The life time of tempdata is little bit tricky. It will be available till you read it first time. After you read it, it will be marked for deletion. So in the next request, it won’t available.  However, you can extend it’s life time by using keep and peek method.
Readers, did i missed anything? Share your feedback as comments.



Monday, October 10, 2016

ASP.Net : Binding Dropdown in ASP.Net

By Francis   Posted at   7:55 PM   Dropdown Control in Asp.Net No comments
Binding dropdown is a common need in ASP.Net. The below code snippet is used to bind the datatable values to the dropdown list.

Markup:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DropDownList runat="server" ID="ddlCity">
            </asp:DropDownList>
        </div>
    </form>
</body>
</html>

Code behind:

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                //Substitute your DB and Server name below
                string conString = @"Data Source=Your_DBServer_Name;Initial Catalog=Your_DB_Name;Integrated Security=True";
                DataTable dtCity = new DataTable("City");
                // Create Connection and get the DB values
                using (SqlConnection connection= new SqlConnection(conString))
                {
                    SqlCommand command = new SqlCommand(conString,connection);
                    command.CommandText = "Select city_code,city_description from tblCity";
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    adapter.Fill(dtCity);
                }
                // Set the Datasource
                ddlCity.DataSource = dtCity;
                ddlCity.DataValueField = "city_code";
                ddlCity.DataTextField = "city_description";
                // Finally Bind it
                ddlCity.DataBind();
            }
        }

Tuesday, August 2, 2016

ASP.Net MVC - ViewBag, ViewData and Tempdata

By Francis   Posted at   9:08 PM   ASP.Net MVC No comments



                  As an ASP.Net MVC developer, you may frequently involved with these terms like Tempdata, viewdata and viewbag. In this post, I’m going to discuss about what are they and what are the main difference between them.

ViewBag:

  1. ViewBag is dynamic in nature.
  2. There is no type casting needed.
  3. Life time lasts only for the current request.

View Data:
  1. ViewData is stored as a dictionary. You can store a value using a key.
  2. Type casting is needed, when you retrieve.
  3. Life time lasts only for the current request.

Tempdata:

  1. It’s also store the value using key.
  2. Need type casting when the stored value retrieved.
  3. The life time of tempdata is little bit tricky. It will be available till you read it first time. After you read it, it will be marked for deletion. So in the next request, it won’t available.  However, you can extend it’s life time by using keep and peek method.

Hope this helps!

Sunday, July 17, 2016

Visual Studio 2015 : Unable to open .CSHTML files

By Francis   Posted at   1:19 AM   Visual Studio Tips and Tricks 6 comments
                               
Unable to open CSHTML File in VisualStudio
                                 Visual studio 2015 is very cool IDE. It offers more and more benefits to increase the productivity of a developer. For my local development I’m using VS 2015 “Community” Edition. Also, I have updated with latest “Update 3” from here.

The Problem:
                         But after some days,  when i want to open a .cshtml file in my solution, VS throws some strange isssue, that is a pop up throws with the message “"Operation could not be completed. Invalid Pointer."

The Solution:
                     I’m not pretty much sure, this error is because of “Update 3”. But i soloved this issue by following the below steps:

  1. Close your VS instance
  2. Open the “Run” dialog (by pressing the short cut Windows Key +R).
  3. Type “%LocalAppData%” (without quotes).
  4. It will open the path “C:\Users\YOURUSERNAME\AppData\Local” in that navigate to “Microsoft –> Visual Studio –> 14.0 –>ComponentModelCache”.
  5. It contains some “cache” files, just delete them all.
  6. Now open the VS 2015 again. You can open the .cshtml files, without any problem.
The above trick, worked for me. This issue also discussed in this github thread. There are various solutions disscused over there, but i found this one is working for me, which is among one they discussed.

If you are one of the victim, hope this post may be useful for you!  Smile
Connect with Us