Banner Ad

Wednesday, October 12, 2016

ASP.Net MVC : TempData - A Closer Look

By Francis   Posted at   1:43 PM   TempData and 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 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

Wednesday, July 13, 2016

WCF : Service Configuration Editor

By Francis   Posted at   3:44 PM   WCF No comments
WCF ConfigEditor                           

                  Windows Communication Foundation involves lot of configuration apart from service coding. Configuring the WCF service is a tedious process also. In order to configure the WCF Services, we need to put our hand mostly on the web.config file, where all the configuration elements resides. As a WCF service developer, I know it is little bit tedious process to configure an simple binding element in the configuration section.

In order to simplify (as much as possible) the configuration process, Microsoft provides an utility to configure the WCF service called “WCF Service Configuration Editor”, which is available as a built –in utility with Visual Studio.

In this particular post, i’m going to explain how to use the WCF Service Configuration editor and how to set different end points with it.

Open WCF Configuration Editor:
                             You can open the WCF Configuration Editor using the menu “Tools –> WCF Configuration Editor”. Otherwise, you can right click on the Web.config file and select “Edit WCF Configuration” on the context menu.

 Create Binding:

1. In the WCF Config Editor, select “Bindings” in the left “Configuration” tree view and click the “New Binding Configuration” link button.

Add Binding Configuration
2. It will open the “Create a new binding” dialog. In this select the respective binding you want. For this, example i will go with “Basic Http Binding” option and then click “OK”.


3. WCF Cofig Editor, will provide the all the attributes in the table format
under the “Binding” tab. You can configure the attribute by setting the valid values. I have set the “Name”  as “Sample Http Binding”.
Configure Binding Attribute

4. If you select “Security” tab, security related attributes are populated as a table format,where you can set the values related to security.

Security Settings

Create End Point:

1. Select the "Endpoints” node in the “Configuration” treeview. Then click “New Client Endpoint” link button.


2. Previously we have created “Basic Http Binding”, So we need to select the “binding” as “Basic Http Binding”.
                                      

3. For “Contract” attribute value, click the browse button and select the WCF service’s dll location. It will extract the Contract from the dll and put it there. Otherwise, you can manually set it.
4. Set the “Address” attribute as the web service location, that is the url, where the WCF service was hosted.
I have set the mandatory attribute alone in the above steps. There are lot of options will be available under the “Identity” tab. if you need any one of these you can set it.

So we are good with our configuration, just save it using “File –> Save”. As a result, the “Web.config” file will be updated with the values which we have configured just now.


Web.config with configured binding and endpoint
As a whole, if you are going to configure some complex binding at this time “WCF Configuration Editor” really helpful!

Readers! I hope this article is helpful. Please let me know your thoughts as comments!

Tuesday, May 3, 2016

Conventional File Uploading in ASP.Net

By Francis   Posted at   5:12 PM   ASP.Net No comments
This post is going to give some basic ideas about file uploading in ASP.Net. Mostly every data driven web site will provide this feature. Also, every ASP.Net developer face this kind of requirement at least once in his/her developer life.



Note:
      The file upload control renders slightly/completely different from browser to browser. If you want to give a consistent UI, you can check my previous post here.

If you want to upload a file in ASP.Net, it is very simple. You need to include “File Upload” control on your form and place a command button, which triggers the upload process and save the respective file in the specified location on the server.


<div> 
           <asp:FileUpload runat="server" ID="fileUploader" AllowMultiple="false" /> 
           <br /> 
           <asp:Button runat="server" Text="Upload" ID="btnUpload" OnClick="btnUpload_Click" /> 
</div>

On the code behind you should include the below lines:

protected void btnUpload_Click(object sender, EventArgs e)    
       {     
           if(fileUploader.HasFile)     
           {     
               fileUploader.SaveAs(Server.MapPath(@"~\UploadedFile\")+ fileUploader.FileName);     
           }     
       }     


Note:
In the above code snippet, when you click the button, it will save the file in a specified location on the server. As per the above code, it looks for the directory “UploadedFile” in the server. So you need to create the directory on your application, before executing the code, otherwise the application will throw an error while run.

Upload specific File Types:
In some cases, we may want to force the user upload only the specific file types. This is an inevitable scenario for the professional programmers. In this case, we should validate the file types, if it pass then we can go with upload. Otherwise, the user will be notified by an “error” message. In order to validate, I’m going to use the built-in ASP.Net validation control.

<div> 
            <asp:FileUpload runat="server" ID="fileUploadExcel" AllowMultiple="false" /> 
            <br /> 
            <asp:Button runat="server" Text="Upload" ID="btnUploadExcel" OnClick="btnUploadExcel_Click" /> 
            <asp:RegularExpressionValidator runat="server" ControlToValidate="fileUploadExcel" 
                ValidationExpression="^.*\.xls[xm]?$" 
                ErrorMessage="Please upload excel file only"></asp:RegularExpressionValidator> 
</div>


The code behind not much changed compare to the previous one.

protected void btnUploadExcel_Click(object sender, EventArgs e)    
        {     
            if (fileUploadExcel.HasFile)     
            {     
                fileUploadExcel.SaveAs(Server.MapPath(@"~\UploadedFile\") + fileUploadExcel.FileName);     
            }     
        }

Restrict File Size:
In some cases, we need to restrict the file size. Say for example, we may need to force the user to upload an excel file not more than 1 MB. At this case, we should validate this one from the server as shown below:

protected void btnUploadExcel_Click(object sender, EventArgs e)    
      {     
          if (fileUploadExcel.HasFile)     
          {     
              int fileSize = fileUploadExcel.PostedFile.ContentLength;     
              if (fileSize <= 1048576)     
                  fileUploadExcel.SaveAs(Server.MapPath(@"~\UploadedFile\") + fileUploadExcel.FileName);     
              else     
              {     
                  lblError.Text = "File size exceeds more than 1 MB.";     
              }     
          }     
      } 

Upload Multiple Files:
In some cases, we may need to upload multiple files. ASP.Net gives an easy way to achieve this. The file upload server controls had a property called “AllowMultiple”, which is a boolean value (either true or false). By turn it as “true”, the file upload control control allows you to select multiple files.

<div> 
<asp:FileUpload runat="server" ID="fileUploadMultiple" AllowMultiple="true" /> 
<br /> 
<asp:Button runat="server" Text="Upload" ID="btnUploadMultiple" OnClick="btnUploadMultiple_Click" /> 
<asp:RegularExpressionValidator runat="server" ControlToValidate="fileUploadMultiple" 
ValidationExpression="^.*\.doc[x]?$" ID="RegularExpressionValidator1" 
ErrorMessage="Please upload word file only"></asp:RegularExpressionValidator> 
<asp:Label runat="server" ID="Label1" Style="color: red;"></asp:Label> 
</div>

In the code behind, the code like below. It get the files and loop thru the selected files and check the file size then store it in the particular path.

protected void btnUploadMultiple_Click(object sender, EventArgs e)    
{     
    if (fileUploadMultiple.HasFile)     
    {     
        HttpFileCollection files = Request.Files;     
        for (int i=0;i < files.Count;i++)     
        {     
            HttpPostedFile file = files[i];     
            if(file.ContentLength >0)     
            fileUploadMultiple.SaveAs(Server.MapPath(@"~\UploadedFile\") + file.FileName);     
        }     
    }     
}    


I hope this post gives an some basic understanding and standard validations during the File upload in ASP.Net. Let me know your thoughts as comments. Happy Coding! Smile

Sunday, March 13, 2016

Identify the ASP.Net Version of an ASP.Net Application from Browser

By Francis   Posted at   2:12 PM   Web Development No comments
                    

                        In my previous article, i explained about how to use IE Developer tool bar. As a web developer, whenever I browse a “cool” website, i always want to know about what type of technology behind this. As an ASP.Net developer, in this post, i’m going to discuss about how to identify a particular website is built with ASP.Net or Not from the popular browsers like IE, Chrome and Firefox. There are various ways exist, I’m here listed few of them.
Analyze the Source Code:
                       If a website is built with ASP.Net Webforms you can identify it by review the “markup” source code from the browser. If the website built with web form then you can find the hidden element called “viewstate” in the source code. This will hint that the page you are viewing is developed using ASP.Net Web Form. 
                     This is the easiest way to find whether the website you are viewing built with ASP.Net web form or not. But this technique, will not tell the version of the ASP.Net. If you want, to know about the version information also then you need to follow any one of the below ways.

Use third party plugins:
                    Yes! There are third party browser plugin also available for this purpose. You can find the one in the below url: http://builtwith.com/toolbar
                    This plugin is available for most of the popular browsers like Firefox, Chrome and Safari except IE, when i write this post. Just include this on your browsers and you can find out the technology behind with the currently rendered on the browser.
Using Built with Addon
Using Developer Toolbar:
                         IE doesn’t require any plugins or add-ons. You can find the technology behind this using the built-in tool called “IE Developer Toolbar”. This toolbar, contains a tab called “Network”. In this tab, you can find the necessary detail.

Read : How to use IE Developer Toolbar.



Using Fiddler:
                     As all of us know that Fiddler is a famous Web Debugger, which is also provide the facility to analyse the response header elements as the previous one. If you don’t have Fiddler you can download it from this url: https://www.telerik.com/download/fiddler



Readers, hope you enjoy this post. Let me know your thoughts as comments!

Thursday, March 10, 2016

F12 Developer Toolbar in IE– A Good Rescuer

By Francis   Posted at   8:25 PM   IE Developer Toolbar No comments


                             As a web developer, every one will dealt with Internet Explorer. Since our ultimate final output will be render the proper “angle brackets” in browser. In some cases, we may find difficult to debug the rendered HTML. At that time, F12 developer toolbar comes as a rescuer. In this tutorial i have used Internet Explorer Version 10. If you are using the next versions of IE, the look and feel of the toolbar vary slightly, but there is no functional changes that are discussed here. :)

So what is F12 Developer Toolbar:
                           F12 Developer Toolbar is a built-in add-on with Internet Explorer. It will popup from IE when you press F12 Key on your keyboard. Alternatively you can get it by clicking “Tools –> F12 developer tools”. By default, it will be stick with the bottom of IE. In the following section I have mentioned the the uses of F12 Developer toolbar.

F12 Developer Toolbar
Using F12 Developer Toolbar:
There are lot of uses of F12 Developer Toolbar. In this article I am going to highlight few of them. With F12 Toolbar you can:
1) Select DOM Elements
2) Debug Javascript
3) Identify the Javascript errors or missing HTML tag errors on your files.
4) Trace the applied CSS classes.
5) Analyze the Network Timing

Set up the code:
In order to explain the above functionalities I have used the below HTML markup. It’s a simple ASPX file with a textbox and a button. The text box accepts an integer value and validate it and show the alert box accordingly.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="SessionDemo.Home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Home.css" rel="stylesheet" />
    <script type="text/javascript">
        function validateAge()
        {
            var age = document.getElementById("txtAge").value;
            if(isNaN(age))
            {
                alert("You have entered valid age");
            }
            else {
                alert("You have entered invalid age");
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Enter Age: 
            <input type="text" id="txtAge" />
            <input type="button" id="btnValidate" value="Validate Age" onclick="validateAge();" class="btn"/>
        </div>
    </form>
</body>
</html>

Select DOM Elements:
This is an important feature of Developer Toolbar. You can easily navigate the particular DOM elements by clicking on it on the IE. So that you can easily spot the respective "piece of markup" for that element in the whole page. This facilitate to easily fix the issues related to design.In order to select the DOM element, you need to do the following:
  1. Select the Arrow mark icon (Select Element by click) on the top left in Developer toolbar.
  2. Now you can select any element in the page(Elements are highlighted with the rectangle boxes).
  3. When you select the element, soon the IE Developer toolbar will highlight the particular markup. Refer the below screen shot.

Select DOM Element
Debug JS using F12 Toolbar:
In order to debug the JS, just run the above HTML page in IE and follow the steps:
1) Open F12 Toolbar
2) Go to “Script” tab, where the entire markup listed.
3) Place the breakpoint on the javascript. (Please refer the below screen how to set the breakpoint)
4) Click on the “Start debugging” button.
5) Since the Js function is triggered when you click the button. Just click the button to start the debugging.
Setup the Breakpoint
Debug JS in IE Developer Toolbar

Identify the Javascript errors:
                  In some case as a developer we may do some mistakes typo error. As an example, refer the below code at line no 10, wrongly typed as value() instead of value (which is get the text box value). There is no such method is available in JS. It will be easily identified by IE developer toolbar. The point here is, these type of Javascript related issues easily identified by IE Developer tool bar.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="SessionDemo.Home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Home.css" rel="stylesheet" />
    <script type="text/javascript">
        function validateAge()
        {
            var age = document.getElementById("txtAge").value();
            if(isNaN(age))
            {
                alert("You have entered valid age");
            }
            else {
                alert("You have entered invalid age");
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Enter Age: 
            <input type="text" id="txtAge" />
            <input type="button" id="btnValidate" value="Validate Age" onclick="validateAge();" class="btn"/>
        </div>
    </form>
</body>
</html>

In order to identify these kind of issues, you should follow the below steps:
1) Render you page in IE.
2) Open F12 toolbar.
3) Select the “Console” tab.
4) Since this JS function is called when you hit the button “Validate Age”. So just click on it.
5) You can see the error messge and when you click on the hyper link detail it will point out the repective line that causes the error.
Identify Javascript Error

Identify missing HTML tag errors:
                                Most of the time we may not closed the end tag of the HTML element. Most of the time it will not cause any issues luckily. In some worst cases, it will collapse all the design of your page. IE Developer tool bar is very much helpful in this case also. It will throw a warning message in the “Console” if your markup missed out anything like missing closing tag.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="SessionDemo.Home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Home.css" rel="stylesheet" />
    <script type="text/javascript">
        function validateAge()
        {
            var age = document.getElementById("txtAge").value();
            if(isNaN(age))
            {
                alert("You have entered valid age");
            }
            else {
                alert("You have entered invalid age");
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Enter Age: 
            <input type="text" id="txtAge" />
            <span><span>
            <input type="button" id="btnValidate" value="Validate Age" onclick="validateAge();" class="btn"/>
        </div>
    </form>
</body>
</html>

As you see the above code missing a closing tag in the “span” element at the line no 26. When you run the page you can see the warning message in the console like below:
Identify Missing HTML Tags using Developer Toolbar

Trace CSS:
                  In some cases, we may require the to change the applied css, in the page to achieve the exact design as per requirement we have. Normally, as a developer we render the page in browser and comes to the source code and adjust the CSS classes then again go to and run the page in browser to check the changes.
                 In these kind of scenario, F12 developer tool bar plays a vital role to save developer’s time. With the help of F12 developer tool bar, you can edit your applied CSS classes and see the result immeditately in the browser.This feature always helps a lot in terms of saves our time.
                 For demo purpose, i have used a simple CSS file and included in the ASPX file.In order to edit/trace the applied CSS classes, you need to follow the below steps:
1) Render you page in IE.
2) Open F12 toolbar. (by press F12 toolbar)
3) Select the “CSS” tab, it will list all the CSS elements used in the page.
4) You can remove the applied style by uncheck the check box. Also, you can create your own rule and apply and view it the browser itself.
Trace CSS using IE Developer Toolbar

Analyze Network Timings:

In some scenario, you may need to want to know about the network timings that took for each requests. These kind of analysis are helpful to do performance related improvements on the browser end. In such case, the "Network" tab in the IE Developer toolbar plays a vital role. You need to follow the below steps to work with network tab:
1) Render you page in IE.
2) Open F12 toolbar. (by press F12 toolbar)
3) Select the “Network” tab.
4) Click “Start debugging” (When you click, the button text will be modified as “Stop debugging”).
5) Then you need reload the page (by pressing F5). This is because whenever the page loads at that time only the files are downloaded from the server.
Network Tab in IE Developer Toolbar


About Other Browsers:
                  Other popular browsers also provide these kind utilities. Chrome offers in the name of "Developer Tools" and Firefox provide as "Inspect Element". These tools also provide the same kind of facilities like IE Developer Toolbar. 
 
I hope you enjoyed this tutorial. For beginners it will give some good idea about the IE Developer toolbar.  Let me know your thoughts as comments. :)

Sunday, February 7, 2016

Visual Studio Tips and Tricks -13 : Debugging with Visual Studio

By Francis   Posted at   3:15 PM   Visual Studio Tips and Tricks No comments
Visual Studio is a great IDE for developing all type of Microsoft desktop/web stack applications. There is no doubt on that!. One of the main feature provided in Visual Studio is it’s capability provide more options to debugging the applications. In this post I explained some basic concepts about debugging in Visual Studio.


You can also check my other Visual Studio Tips here.

Setup the environment:

In this post I’m using Visual Studio 2015 Community edition. Based on your version of Visual studio some options may differ. For simple and neat explanation, here I’m going to use a simple for loop C# code snippet.

So What is breakpoint?
When you run the program in Visual Studio IDE, if you want to check the execution of a particular routine or function at that time you can set the breakpoint. Probably, it set before to run the application. So when the program executes, the breakpoint hits and the program waits there. So that you can step into the program and take a deep look into the code and check the values there itself. This is the main advantage of breakpoints.

Set normal Breakpoint:
Set the breakpoint in an application is very simple. You can hit the F9 key or you can click on the left most border in Visual Studio. It will keep the break point on the particular line.
After setting the break point, Visual Studio indicate the particular line with the Red color and preceded with a dot like below.

Breakpoint-in-VisualStudio
Breakpoint-in-VisualStudio

In these kind of break points, it will hit without any conditions. So whenever, the execution cross the line it will simply hit there.

Set Conditional Breakpoint:
So as we discussed in the previous section,say for example, if we set the break point with in a loop it will hit the break point without any condition. So the break point is hit often. Instead of this, we may want to set some conditions. Let’s see how we can do it.

1. Right click on the break point and select “Conditions…” in the context menu.
Conditional-Breakpoint-Menu
Conditional-Breakpoint-Menu
2. Visual Studio 2015 offers the below “Breakpoint Settings” window to set up the condition.
Conditional-Breakpoint-Window
Conditional-Breakpoint-Window
3. Here I’m going to set the “Conditions” as : When the counter value(i) is greater than 5 at that time it will hit the break point. That means, till the value of the counter value is 5, it will not hit. After that it will hit.
Setting-Conditions
Set-Conditions
In some cases you may want to track based on some process id or thread id etc. Visual studio also give options for this.

Breakpoint-Window-Filter
In some cases, we want to count the “Hit count”,meant whenever the break point hits it will consider as a hitcount. You can specify it by selecting “Hit Count” list item as below:
Breakpoint-Window-HitCount
Breakpoint-Window-HitCount

Set Actions:
“Breakpoint Settings” window also offers that log message to Output window. At that you can make use of “Actions”. There are some special keywords are there, which have a special meaning when you use in the “Action” text box.

Breakpoint-Window-Action-SpecialKeyword
Breakpoint-Window-Action-SpecialKeyword
When you specify Action alone, there is a checkbox named “Continue execution”, if you check this the breakpoint will not hit. You can see the message in the “Output Window”.
Breakpoint-Window-Specify-Action
Breakpoint-Window-Specify-Action
Breakpoint-Window-Result-in-OutputWindow
Breakpoint-Window-Result-in-OutputWindow
  In the above action, we specify the special keyword "$Function", which prints the current function name as you see in the above screen shot.

Disable Break points:
In some cases, you may want to continue the execution of your program without hitting the breakpoints and later cases you may need them. At that time you can use the "Disable Breakpoint" option by using the short cut key "Ctrl + F9" key. Later cases, you can use the same short cut key to "Enable Breakpoint". You can make use of these options during run time also.

Disabled-Breakpoint
Disabled-Breakpoint
Readers, hopefully this tutorial helps you to understand about the various debugging options provided by Visual Studio. Let me know your thoughts as comments. Happy programming!



Wednesday, January 6, 2016

Replace Special character from string using Regular expression in C#

By Francis   Posted at   6:04 PM   CodeSnippets No comments
In one of the forum post, the poster asked to
  1. Remove all the special character
  2. Then Remove the space and replace with _ (underscore) character
Say for example, if he gave, the input string as “Levi Jeans (Blue) & yellow 101 – 150Ah” and the output he wants as “Levi_Jeans_Blue_yellow_101_150ah”.
Solution:

            string yourInput = "Levi Jeans (Blue) & yellow 101 - 150Ah"; 
            Regex rgx = new Regex(@"[^a-zA-Z\d\s]"); 
            // Replace Special Charater and space with emptystring 
            string finalOutput = rgx.Replace(yourInput,""); 
            Console.WriteLine(finalOutput); 
            Regex rgx1 = new Regex("\\s+"); 
            // Replace space with underscore 
            finalOutput = rgx1.Replace(finalOutput, "_");

Monday, January 4, 2016

Open Live Writer–An alternative for Windows Live writer

By Francis   Posted at   4:55 PM   Open Live Editor No comments
                          Open Live Writer

                     For the last couple of year, i have used a windows essential tool called “Windows Live Writer” for blogging. Yes! It’s made my job easier. It reduces huge amount of work regarding formatting, insert images etc., in my blog post. Literally, I’m a big fan of it.
                        But most recently, Google changed it’s authentication mode and adopt a new authentication technique. So whenever you tried to post/publish a draft you will get the below error:
WindowsLiveEditor_Issue
                         As a remedy, I Googled and Binged a lot and find an another alternative called “Open Live Writer”. You can download it from here. It’s a opensource editor, developed by a group of people inside and outside (.NetFoundation) Microsoft. If you want to participate you can get the source from: https://github.com/OpenLiveWriter/OpenLiveWriter. If you want to know about more Scott Hanselman’s post is very much helpful, which discusses removed features and features on the way in OLW etc.,

                          One of the main draw back that I found in OLW(Open Live Editor) is, it missed out the “Automatic spell check”, which I thought all bloggers love that. Another good news is you can run OLW and Windows Live Editor side by side.As a tweak for the “Spell Check Issue”, I’m still uses Windows Live Editor to draft my blog and publish it by OLW. Hope this tweak is still worth mentioning! wlEmoticon-smile[2]

Hope this post will help for someone! Smile

December Month Winner in C# Corner

By Francis   Posted at   11:37 AM   CSharpCorner No comments
                       DecemberMonthWinner


                                 I’m very much happy to announce that, I’m also one of the monthly winner in C#Corner for the month December 2015. This month award is something special to me since third time in a row, I received this award. I’m very much happy and thankful to all of my readers,friends and colleague who are all always improves me a lot!

Sunday, January 3, 2016

Got My New Year Gift : Officially CSharpCorner MVP

By Francis   Posted at   10:57 AM   MVP No comments
                              CSharpCorner_MVP_2016
                            I’m very much happy to announce that I got awarded as C# Corner MVP for 2016. I officially received a mail from C# Corner on 2nd Jan 2016. I believe this is one of my biggest milestone achievement in my carrier, since this is my first MVP award. This award really induce me more to achieve new heights within ASP.Net community. Without my family support this award is not possible, especially my Mother, Dad, “Lovely” Wife and my Son “LittleMaster” Subin. My hearty thanks to C# Corner Team, Friends and my colleagues!!! Congrats to all the other winners also,
                   Personally, I want to dedicate this award to my close “late” friend SathyaSeelan. Really i miss you Sathya, I believe you are always with me!
Connect with Us