Monday, 2 August 2021

save role master page in asp.net c sharp πŸ”₯πŸ”₯πŸ‘ŒπŸ‘Œ

   

How to save role master page in asp.net c sharp

           Overview:

This article explains how to save a role master form page data.  we have started a new project for learning asp.net. The project name is IT Management System and given Youtube link IT Management System (IMS Session-4) The following steps here.πŸ‘‡πŸ”₯

         Download Code: πŸ‘‰ ProjectCodeZipfile 

              Step 1:

                  ✍ Open Already Created IT Management System Project Folder Location

                 ✍ It's open in visual studio 

          

open existing project in asp.net


Figure-1 πŸ‘†
                       
               Step 2: 

                Create Business Objects in IT Management System

                Write following Code in Business Objects 
                           

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IMS.BusinessObjects
{
    public class AdminBO
    {
        public int RoleId { get; set; }
        public string Role { get; set; }
        public string Description { get; set; }
    }
}

 

           Step 3: 

                Create Business Layer in IT Management System

                Write following Code in Business Layer 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using IMS.BusinessObjects;

using IMS.DataLayer;

namespace IMS.BusinessLayer

{

    public class AdminBAL

    {

        AdminDAL objadmindal = new AdminDAL();

        public int InsertRole(AdminBO adminBO)

        {

            return objadmindal.InsertRole(adminBO);

        }

    }

}

       Step 4: 

                Create Data Access Layer in IT Management System

                Write following Code in Data Access Layer

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using IMS.BusinessObjects;

using IMS.Common.Library;

using System.Configuration;

using System.Data;

using System.Data.SqlClient;

namespace IMS.DataLayer

{

    public class AdminDAL

    {

        AdminBO objadminbo = new AdminBO();

        SqlConnection con = new SqlConnection(AppConfig.ConnectionString);

        SqlCommand objcmd = new SqlCommand();

        public int InsertRole(AdminBO adminBO)

        {

            int affectcount = 0;

            try

            {

                using (con)

                {

                    objcmd.CommandText = "prInsertUpdateRole";

                    objcmd.CommandType = CommandType.StoredProcedure;

                    objcmd.Parameters.AddWithValue("@Id",adminBO.RoleId);

                    objcmd.Parameters.AddWithValue("@Role",adminBO.Role);

                    objcmd.Parameters.AddWithValue("@Description",adminBO.Description);

                    objcmd.Connection = con;

                    con.Open();

                    affectcount = objcmd.ExecuteNonQuery();

                    con.Close();

                }

            }

            catch (Exception ex)

            {

                throw new Exception(ex.Message);

            }

            return affectcount;

        }

    }

}


       Step 5:  

            ✍ Create Role Master Page following HTML source code in IT Management System


<%@ Page Title="" Language="C#" MasterPageFile="~/MainMasterPage.Master" AutoEventWireup="true" CodeBehind="RoleMaster.aspx.cs" Inherits="ITManagementSystem.RoleMaster" %>


<%--<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>--%>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">


    <div class="content-wrapper">

        <div class="row">

            <div class="col-12 grid-margin stretch-card">

                <div class="card">

                    <div class="card-body">

                        <h4 class="card-title">Role Master</h4>


                        <div class="row">

                            <div class="col-lg-1"></div>

                            <div class="col-lg-2">

                                <label for="exampleInputName1">Role</label>

                            </div>

                            <div class="col-lg-5">

                                <asp:TextBox ID="txtboxrole" class="form-control" runat="server"></asp:TextBox>

                            </div>

                        </div>



                        <div class="row mt-2">

                            <div class="col-lg-1"></div>

                            <div class="col-lg-2">

                                <label for="exampleInputEmail3">Description</label>

                            </div>

                            <div class="col-lg-5">

                                <asp:TextBox ID="txtboxDescription" class="form-control" runat="server"></asp:TextBox>

                            </div>


                        </div>

                        <div class="form-group mt-2">

                            <div class="col-lg-4"></div>

                            <div class="col-lg-8 text-center">

                                <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" class="btn btn-primary mr-2" Text="Save" />

                                <asp:Button ID="btnClear" runat="server" class="btn btn-light" Text="Clear" />

                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    </div>


    


</asp:Content>


       Step 6:

            ✍ When clicking Save button  for Role Master Page following C# code in IT            Management System


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IMS.BusinessObjects;
using IMS.BusinessLayer;

namespace ITManagementSystem
{
    public partial class RoleMaster : System.Web.UI.Page
    {
        AdminBO adminBO = new AdminBO();
        AdminBAL objadminbal = new AdminBAL();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int affect = 0;
            try
            {
                adminBO.Role = txtboxrole.Text;
                adminBO.Description = txtboxDescription.Text;
                affect = objadminbal.InsertRole(adminBO);
                if(affect > 0)
                {
                    Response.Write("<script>alert('Role is saved successfully..!')</script>");
                }

            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}


       Final Output: 

save role master page asp.net


         More Details:  

            IMS -Session-4 video



Video Link :  https://www.youtube.com/watch?v=UrasVBfKu-E


             
       Thank you for reading my articles any comments post below. πŸ‘‡πŸ‘‡πŸ’“πŸ’“ Thank you..!!πŸ‘πŸ‘ŒπŸ‘†πŸ™πŸ™

No comments:

Post a Comment

Angular Course Class Day-4 in English

  Angular Course Class Day-4 Note: You have to add following code your project and run check the result. Angular Material UI Design: CSS...