Pages

Access server side function using JQuery.

Saturday, 6 July 2013
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Website1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script lang="javascript" src="JQuery.js" type="text/javascript"></script>
    <script lang="javascript">
            function chk()
            {
            $.ajax (
            {
                type: "POST",
                url: "WebForm1.aspx/show",  // show is the name of function 
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                async: true,
                cache: false,
                success: function (msg) 
                {
                    $('#div1').text(msg.d); 
                },
                error: function (x, e)
                {
                alert("The call to the server side failed. " + x.responseText);
                }
            });
                return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="div1" style="width:500px; height:40px; background-color:aqua">

            This is hidable.

        </div>

    <div>
        <asp:TextBox ID="Text"  CssClass="abc" Text="" runat="server"></asp:TextBox>
        <asp:Button ID="btnShow" OnClientClick="return chk();" runat="server" OnClick="btnShow_Click" Text="Javascript" />
    </div>
    </form>
</body>
</html>


Read more ...

Reflection in C#

Wednesday, 26 June 2013

Class.cs
=============

using System;

namespace IT
{
class Employee
{
public string EmployeeName { get; set; }
public string getEmployeeName()
{
return "Srikant";
}
}
class Student
{
public string getStudentName()
{
return "Rahul";
}
}
}

Reflection.cs
=============

using System;
using System.Reflection;

namespace Reflection
{

class MyReflection
{
public void getAssemblyType()
{
Assembly ptr = Assembly.LoadFrom("d:\\Srikant\\Reflection\\Class.dll");
// Return the Information about DLL.
Console.WriteLine(ptr.FullName);
}
public void getMethods(Type objM)
{
MethodInfo[] m = objM.GetMethods();
foreach(MethodInfo m1 in m)
{
Console.WriteLine(m1.Name);
}
}
public void getClasses()
{
Assembly ptr = Assembly.LoadFrom("d:\\Srikant\\Reflection\\Class.dll");
Type[] t = ptr.GetTypes();
foreach(Type temp in t)
{
Console.WriteLine(temp.FullName);
if(temp.IsClass)
{
getMethods(temp);
}
}
// Name : Only returns the class name, but FullName returns Namespace.ClassName
}
public static void Main()
{
MyReflection r = new MyReflection();
Console.WriteLine("Assembly Details");
Console.WriteLine("================");
r.getAssemblyType(); //Return the assembly details
Console.WriteLine("                              ");
Console.WriteLine("Classes & Method Details");
Console.WriteLine("========================");
r.getClasses(); //Return the method names
}
}
}

Read more ...