Translate

Wednesday 30 July 2014

Application pool

  1. An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Any Web directory or virtual directory can be assigned to an application pool. Every application within an application pool shares the same worker process.
    isolatation:
    Application pools allow you to isolate your applications from one another, even if they are running on the same server. This way, if there is an error in one app, it won't take down other applications.
    Additionally, applications pools allow you to separate different apps which require different levels of security, reliability, and availability.
    Main Point to Remember: 
    1. Isolation of Different Web Application 
    2. Individual worker process for different web application 
    3. More reliably web application 
    4. Better Performance

Wednesday 23 July 2014

Calling a static "page method" from Javascript using MS AJAX

This is designed for v1.0.61025.0 of AJAXExtensionsToolbox.dll

Enable Page Methods on your ScriptManager

Set the EnablePageMethods attribute to true

<asp:ScriptManager ID="ScriptManager1"
    EnablePageMethods="true"
    EnablePartialRendering="true" runat="server" />


Mark your method as static and give it the WebMethod attribute

The method has to be declared static. It must also be marked with the WebMethod attribute. You'll probably find that you need to include System.Web.Services

using System.Web.Services;

[WebMethod]
public static string MyMethod(string name)
{
    return "Hello " + name;
}

Call it from Javascript

To call the method from javascript you need to append PageMethods. to the front of the method name.

<script>
    function test() {
        alert(PageMethods.MyMethod("Gksamy"));
    }
</script>

Thursday 17 July 2014

Passing values from C# Code Behind to JavaScript.

You can use var variable name = "<%=this.variable%>"  to get value from aspx.cs. Variable must be public , protected in aspx.cs file.

For example, you can use: var date=”<%=DateTime.Now%>”;  to get the server time.

Sunday 13 July 2014

MVC4 Registration form with Client and Server Side Validation

http://www.dotnet-tricks.com/Tutorial/mvc/H1VF301212-MVC4-Registration-form-with-Client-and-Server-Side-Validation.html

http://www.c-sharpcorner.com/UploadFile/c25b6d/creating-the-registration-form-in-Asp-Net-mvc-3-using-razor/

http://www.c-sharpcorner.com/UploadFile/b19d5a/custom-user-login-and-registration-page-in-Asp-Net-mvc3-with-razor-and-entity-framework/

http://www.codeproject.com/Articles/639695/Getting-Started-with-Razor-View-Engine-in-MVC

MVC 2
http://www.codeproject.com/Articles/207797/Learn-MVC-Model-View-Controller-step-by-step-in-7

Friday 11 July 2014

ViewData vs ViewBag vs TempData vs Session

ViewData

  1. ViewData is a dictionary object that is derived from ViewDataDictionary class.

    1. public ViewDataDictionary ViewData { get; set; }
  2. ViewData is a property of ControllerBase class.
  3. ViewData is used to pass data from controller to corresponding view.
  4. It’s life lies only during the current request.
  5. If redirection occurs then it’s value becomes null.
  6. It’s required typecasting for getting data and check for null values to avoid error.

ViewBag

  1. ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.
  2. Basically it is a wrapper around the ViewData and also used to pass data from controller to corresponding view.
    1. public Object ViewBag { get; }
  3. ViewBag is a property of ControllerBase class.
  4. It’s life also lies only during the current request.
  5. If redirection occurs then it’s value becomes null.
  6. It doesn’t required typecasting for getting data.

TempData

  1. TempData is a dictionary object that is derived from TempDataDictionary class and stored in short lives session.
    1. public TempDataDictionary TempData { get; set; }
  2. TempData is a property of ControllerBase class.
  3. TempData is used to pass data from current request to subsequent request (means redirecting from one page to another).
  4. It’s life is very short and lies only till the target view is fully loaded.
  5. It’s required typecasting for getting data and check for null values to avoid error.
  6. It is used to store only one time messages like error messages, validation messages. To persist data with TempData refer this article: Persisting Data with TempData

Session

  1. Session is an object that is derived from HttpSessionState class.
    1. public HttpSessionState Session { get; }
  2. Session is a property of HttpContext class.
  3. Session is also used to pass data within the ASP.NET MVC application and Unlike TempData, it never expires.
  4. Session is valid for all requests, not for a single redirect.
  5. It’s also required typecasting for getting data and check for null values to avoid error.

Thursday 10 July 2014

How to detect browser close when browser [X] is clicked ? or Window Close Event of Browser

aspx page:

 <script type="text/javascript" language="javascript">

        window.onbeforeunload = closeit;
        function closeit() {
            var closeEvent = false;

            //alert(event.clientY);
            if (event.clientY < 0)
                closeEvent = true;

            if ((closeEvent)) {
                document.getElementById('btnClose').click();
            }
        }
    </script>


 <table>
            <tr>
                <td>
                    <asp:Button ID="btnClose" runat="server" OnClick="closebrowser"
                        Style="display: none" />
                </td>
            </tr>
        </table>

c# page:

public void closebrowser(object sender, EventArgs e)
    {

        try
        {
           // do something

        }
        catch (Exception ex)
        {
          throw ex;
        }

    }

Thursday 3 July 2014

optional and Named parameters: C#

Program that uses optional parameters: C#

using System;

class Program
{
    static void Main()
    {
// Omit the optional parameters.
Method();

// Omit second optional parameter.
Method(4);

// You can't omit the first but keep the second.
// Method("Dot");

// Classic calling syntax.
Method(4, "Dot");

// Specify one named parameter.
Method(name: "Sam");

// Specify both named parameters.
Method(value: 5, name: "Allen");
    }

    static void Method(int value = 1, string name = "Perl")
    {
Console.WriteLine("value = {0}, name = {1}", value, name);
    }
}

Output

value = 1, name = Perl
value = 4, name = Perl
value = 4, name = Dot
value = 1, name = Sam
value = 5, name = Allen