Sunday, 23 March 2014

Calling webmethod from Jquery

Calling the web method from Client side event and Jquery;

You need to first create the webmethod,
Creating the webmethod to add the employee;

[System.Web.Services.WebMethod]
    public static string AddEmployeeDetails(int num, string  Name)
    {
        EmplyeeBAO ObjEmplyeee = new EmplyeeBAO();
        ObjEmplyeee.AddItem(num, Name);
        return "Add";

    }


Call below jqery code to insert the employee data by calling the web method which has written on code behind window;

jQuery.ajax({
            url: 'Default.aspx/AddEmployeeDetails',
            type: "POST",
            data: "{'num' : " + num + ",'Name':" + Name + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function () {
                alert("Start!!! ");
            },
            success: function (data) {
                alert("a");
            },
            failure: function (msg) { alert("Sorry Not inserted!!! "); }
        });

Saturday, 22 March 2014

show page number in gridview

Basically grid view is showing the page number by giving the property to the  allow paging and defined the page size like:

  Code snippet  

<asp:GridView ID="grdCGGoodsDesc" BackColor="White"   runat="server" BorderWidth="1px" AutoGenerateEditButton="false"  PagerSettings-Mode="Numeric" ShowHeader="false" " ShowFooter="true" Width="100%" AutoGenerateColumns="false" AllowPaging="true" PageSize="6" OnPageIndexChanging="grdCGDesc_PageIndexChanging">

  Allow Paging is allowing the pagging of your grid view; PazeSize is defind the number of items display in par page. but when you see on your code it not look very good its looking very awakward and very detractive, like below;


Displaying total and current page in gridview footer

Most of the time User got stuck that how pages there in grid and in which page he is current; The best solution for it that to show the user for his\her current page location in grid view. Just displaying the current page of grid and total number of pages in the grid;

  Code Snippet

@C# Code if you see the code the current page and number of page in grid will display only at the footer of the page from

 e.Row.RowType == DataControlRowType.Footer
 protected void

grdCGGoodsDesc_RowDataBound(object sender, GridViewRowEventArgs e)  
 {         if (e.Row.RowType == DataControlRowType.Footer)      
                 {          
e.Row.Cells[0].Text = "Page <b>" + (grdCGGoodsDesc.PageIndex + 1) + "</b> Of <b>" + grdCGGoodsDesc.PageCount + "</b>";      
}  
}

How to send email in asp.net C#

This summary is not available. Please click here to view the post.

Bind object to dropdownlist

To display the data into the drop down we need to bind the data into Dropdown, data collection might be in the form of Datatable, Dataset, Datareader, Disctionay or List object.

  Binding data in drop of list object; Create a class to bind the objects; 

it is having two property

public class location
    {    
        public int id { get; set; }    
        public string locationName { get; set; }
    }

What is HTTP Module in asp.net

  • What is HTTP Modules?
       HTTP Modules are simple classes that can play themselves into request - processing pipeline.
  • What are method contains in  HTTP Modules ? 
        Crete HTTP Modules, simply create a class that drives from the System.Web.IHTTPModule Interface.
It require to implement two methods, Init & Dispose.
Init - it is primary method you use to implement functionality. It has only one parameter.
public void Init(HttpApplication context
There are some more another methods as below:

How HTTPrequests work in IIS ?

There are Step by Step processes to know how HTTP request works.

1.      If want to be able to interact with the low level processes, such as how the web server processes incoming & outgoing HTTP Request.

2.       Before coming of HTTP Modules and Handlers to work with Web server & to control IIS operation uses forced to create ISAPI Extreme or Filter. Which is not easy due to creating it user need to know about c/c++ knowledge in low level.

3.       IIS is the basic end point for incoming HTTP Request its job is to listen for & validate incoming HTTP Request. Than it routes them to appropriate modules for processing & return any results to the original requestor.

what is HTTP handler in asp.net ?

1.       It is different from HTTP modules not only because of their position in the request- processing pipe line but also because they must be mapped to a specific file extension.

2.       HTTP handlers are the last stop for incoming HTTP Request and are ultimately the point in the request processing pipeline and as responsible to create response.

3.       Generic Handlers: There is generic Handlers file type is providing. Adding this generic handlers to the project with ashx file extensions. The ashx is unique file extensions. It is provided by ASP.Net otherwise we need to add it manually;

4.       Add the Generic Handler file to the project, it add the file with an .ashx extension. The .ashx file extension is the defaut HTTPHandler file extension file extension setup by ASP.Net.

how to create a website in asp.net using c#

Step by step procedure, how to create web site in ASP.Net;
1-      You have to install any of the Visual Studio software on tour system. It will give you full package to work with windows and web applications.
2-      I have installed VS2010 in my Laptop, I am going through how you can create a web site in VS2010.
3-      Once you install it will appear in your start program like in Image. Just click on the Icon.

How to split string in c# ?

Split means to separate the value to separate the values of string and form array and make it to array value and some time we want to make the array to string value.
Split string into c# to array; suppose you have the string as like Xx Yy Zz,  There  you can split and get the value into array “Xx” “Yy” and “Zz”
Code Snippet  for split string in C#
namespace testSplitString
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "Split string to array"; // string value with space
           
            string[] strSplitValue = str.Split(' '); // split strinf itnto array.
            foreach (string oStr in strSplitValue)
            {
                Console.WriteLine(oStr); // display array valye
            }
        }
    }
}
@Out split  value 
click here to get how to Convert array to string