Using Class File in ASP.NET


Look at the sample and running code for me.

My Class File inside App_Code directory:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for LastLoginDateUpdation
/// </summary>
public class abc
{
        public abc()
        {
                //
                // TODO: Add constructor logic here
                //
        }

    public static object DisplayEmployee()
    {
        string str = null;
        str = "this is sample text";
        return str;
    }
}

Code-Behind File named Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class chat_Default : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        abc xx = new abc();
        string x = abc.DisplayEmployee().ToString();
        Label1.Text = x;

    }
}

FrontEnd File named Default.aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="chat_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

</asp:Content>

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples