Friday, September 21, 2018

Check the current Identity and Reset the Identity

Code Snippet:



// Check the current identity of the table
SELECT IDENT_CURRENT('tablename') 


 //Reset the identity to next incremental value
DBCC CHECKIDENT ('tablename', RESEED, 0)




When RESEED is used then the numbervalue in third argument of the CHECKIDENT is set as current identity for the table. Here in this case RESEED to 0 means 



Calling a WebMethod from User control in ASP.NET

This is a framework limitation, we cannot call the webmethod in the code behind file of user control from ascx file.

However try calling the webmethod in aspx code behind file from the ascx file. This will work

Monday, September 17, 2018

jQuery Ajax GET with params using WebMethod in c#

jQuery Ajax GET with params using WebMethod in c#

Code Snippet:
UI:
            <asp:Button ID="Button1" runat="server" Text="Call Ajax Get" OnClientClick="AjaxCall2();" />


jQuery:

        function AjaxCall2() {
            debugger;
            $.ajax({
                type: "GET",
                url: "AjaxTest.aspx/TestAjaxCallGET?name='Radha'",
                contentType: "application/json; charset=utf-8",
                dataType: "text",
                async: true,
                success: function (response) {
                    alert("Success");
                },
                failure: function (response) {
                    alert("failure");

                }
            });
        }


WebMethod C#

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
        public static string TestAjaxCallGET(string name)
        {
            return name;
        }

jQuery Ajax POST using WebMethod in c#

Code Snippet:

UI:

<asp:Button ID="AjaxCall" runat="server" Text="Call Ajax" OnClientClick="AjaxCall1();" />


jQuery Ajax:

        function AjaxCall1() {
            debugger;
            $.ajax({
                type: "POST",
                url: "AjaxTest.aspx/TestAjaxCall",
                data: '{postParam: "Hello Ajax web method" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                success: function (response) {
                    alert("Success");
                },
                failure: function (response) {
                    alert("failure");

                }
            });
        }

c# WebMethod:

        [WebMethod]
        public static string TestAjaxCall(string postParam)
        {
            return postParam;       
        }




Sample snippet that explains jQuery Ajax POST using WebMethod in c#


Thursday, September 6, 2018

Types of Inheritance in c#

Single Inheritance - Derived class is created from a single base class. SUPPORTED

Multi-level inheritance - Derived class is created from another derived class. SUPPORTED

Multiple inheritance - A derived class is created from more than one base class. NOT SUPPORTED

Multipath inheritance - In this inheritance, a derived class is created from multiple derived classes and each of these derived classes have same base class. NOT SUPPORTED

Hierarchial inheritance - In this inheritance, more than one derived classes are created from a single base. SUPPORTED

Hybrid inheritance - This is combination of more than one inheritance. So depending on type of combination we can say SUPPORTEDor NOT SUPPORTED