Search Your Dot Net Topic

Friday 30 April 2021

Asp.Net Session Practical | Session using Asp.Net WebForm | session in ...



Asp.Net Session  Practical


CODE: login.aspx

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <table>
                <tr>
                    <td>
                        User Name
                    </td>
                    <td>
                        <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                      Password
                    </td>
                    <td>
                        <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit"/>
                    </td>
                </tr>
            </table>
    </div>
    </form>
</body>
</html>



CODE: login.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 Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(txtUsername.Text)  && txtPassword.Text.ToLower() == "abc12")
        {
            Session["LogUserName"] = txtUsername.Text;
            Response.Redirect("dashboard.aspx");
        }
    }
}






CODE: dashboard.aspx

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <h1>Welcome <asp:Label ID="lblUserName" runat="server"></asp:Label> </h1>
    </div>
    </form>
</body>
</html>



CODE: dashboard.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 dashboard : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string UserName = Convert.ToString(Session["LogUserName"]);
        if (!string.IsNullOrEmpty(UserName))
        {
            lblUserName.Text = UserName;
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }
}


asp.net session management example | using session in asp.net C# | what ...





WHAT IS SESSION?

Session provides a facility to store information on server memory not in browser. 

Session created in server memory.

It can store any type of object. (System.Object)






WHY WE NEED SESSION?

HTTP is stateless protocol, its forgot everything after response. 

To keep some data in process we required SESSION.

Session keep our valuable and important data on server,
On any page we can call the same.





ADVANTAGES:
Help to maintain user data all over the application.
Easy to implement.
Store any kind of Object.
Store / Keep each User data store separately.
Its Very Much Secure.




DISADVANTAGES:
Default session timeout is 20 minutes.
Loss of Data when session expired.
More session more burden on server.
Overhead involved in serializing and De-Serializing session data





HOW TO CREATE A SESSION?
SYNTAX:
Session[“NAME OF SESSION”] =  <OBJECT>
EXAMPLE:
Session[“LoginUser”] = txtUserName.Text;
(This will create a SESSION called LOGINUSER.)







HOW TO USE A SESSION?
EXAMPLE:
string UserName = Convert.ToString(Session[“LoginUser”]);
(This will convert session object LOGINUSER into string.)






Thursday 29 April 2021

hyperlink button in asp.net | hyperlink button example | asp.net hyperli...



Code: HyperLink.aspx

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:HyperLink ID="hylnkMyBlog" runat="server" NavigateUrl="https://dotnettutorinmumbai.blogspot.com/">My Training Blog</asp:HyperLink>
        <a href="https://dotnettutorinmumbai.blogspot.com/">My Training Blog</a>
    </div>
    </form>
</body>
</html>





Code: Hyperlink.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 hyperlink : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

LinkButton in asp.net c# | linkbutton href c# | linkbutton example | lin...




Code : LinkButton.aspx

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="lnkbtnTimeNow" runat="server" OnClick="lnkbtnTimeNow_Click">Click for Current Time</asp:LinkButton>
        <br />
        <br />
        <asp:Label ID="lblMsg" runat="server" text="[TIME]"></asp:Label>
    </div>
    </form>
</body>
</html>





Code: LinkButton.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 Linkbutton : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void lnkbtnTimeNow_Click(object sender, EventArgs e)
    {
        lblMsg.Text = "Current Time : "+DateTime.Now.ToString();
    }
}

Monday 26 April 2021

FileUpload Control Asp.Net WebForm | FileUpload using Asp.Net C# | file-...




CODE:  file-upload-example.aspx
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="fuImage" runat="server" />
        <br />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        <br />
        <br />
        <asp:Label ID="lblMsg" runat="server"  Text="[Message]"></asp:Label>

    </div>
    </form>
</body>
</html>







CODE:  file-upload-example.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 file_upload_sample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }



    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if ((fuImage.PostedFile != null) && (fuImage.PostedFile.ContentLength > 0))
        {
            string FileName = System.IO.Path.GetFileName(fuImage.FileName);
            string FileSaveLocation = @"F:\Learning\UserFiles\" + FileName;
            fuImage.PostedFile.SaveAs(FileSaveLocation);
            lblMsg.Text = "File Uploaded Successfully";
        }
    }
}

checkbox in asp.net | asp.net checkbox control | checkbox in asp.net c# ...





 
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>Checkbox Tutorial</h2>

        <strong>Language</strong>
        <asp:CheckBox ID="chkbHindi" runat="server"  Text="Hindi" />
        <asp:CheckBox ID="chkbEnglish" runat="server"  Text="English" />
        <asp:CheckBox ID="chkbMarathi" runat="server"  Text="Marathi" />
        <asp:CheckBox ID="chkbMarwadi" runat="server"  Text="Marwadi/Rajasthani" />
        <asp:CheckBox ID="chkbGujrati" runat="server"  Text="Gujrati" />
    </div>
        <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click"  Text="Select Language & Submit"/>
        <br />
        <br />
        <asp:Label ID="lbllang" runat="server" Text="[Your Language]"></asp:Label>
    </form>
</body>
</html>




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

public partial class checkbox_sample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        string result = string.Empty;
        if (chkbEnglish.Checked == true)
        {
            result = chkbEnglish.Text;
        }
        if (chkbGujrati.Checked == true)
        {
            result = result +"</br>"+ chkbGujrati.Text;
        }
        if (chkbHindi.Checked == true)
        {
            result = result + "</br>" + chkbHindi.Text;
        }
        if (chkbMarathi.Checked == true)
        {
            result = result + "</br>" + chkbMarathi.Text;
        }
        if (chkbMarwadi.Checked == true)
        {
            result = result + "</br>" + chkbMarwadi.Text;
        }

        lbllang.Text = result;
    }
}

Sunday 25 April 2021

Delete Record using Linq To Sql | remove record linq to sql | delete lin...







CODE : delete-friebnd.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="delete-friend.aspx.cs" Inherits="delete_friend" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <table>
           <tr>
               <td>
                   Friend Name
               </td>
               <td>
                   <asp:TextBox ID="txtFriendName" runat="server" Enabled="false"></asp:TextBox>
               </td>
           </tr>

           <tr>
               <td>
                   Mobile 
               </td>
               <td>
                   <asp:TextBox ID="txtMobile" runat="server" Enabled="false"></asp:TextBox>
               </td>
           </tr>
    <tr>
        <td colspan="2">
            <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
        </td>
    </tr>
       </table>
    </div>
    </form>
</body>
</html>




CODE : delete-friebnd.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 delete_friend : System.Web.UI.Page
{
    FriendDataClassesDataContext db = new FriendDataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        var FriendID = Convert.ToString(Request.QueryString["frndid"]);

        var FriendDetail = (from a in db.dbFriends
                                where a.FriendID == Convert.ToInt32(FriendID)
                            select a).FirstOrDefault();

        if (FriendDetail != null)
        {
            txtFriendName.Text = FriendDetail.FriendName;
            txtMobile.Text = FriendDetail.Mobile;
        }

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        var FriendID = Convert.ToString(Request.QueryString["frndid"]);

        var FriendDetail = (from a in db.dbFriends
                            where a.FriendID == Convert.ToInt32(FriendID)
                            select a).FirstOrDefault();

        if (FriendDetail != null)
        {
            db.dbFriends.DeleteOnSubmit(FriendDetail);
            db.SubmitChanges();
        }
    }
}

Update Record Using Linq C# | linq to sql update tutorial | asp.net c# u...



CODE: edit-friend.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit-friend.aspx.cs" Inherits="edit_friend" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
           <tr>
               <td>
                   Friend Name
               </td>
               <td>
                   <asp:TextBox ID="txtFriendName" runat="server"></asp:TextBox>
               </td>
           </tr>

           <tr>
               <td>
                   Mobile 
               </td>
               <td>
                   <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
               </td>
           </tr>
    <tr>
        <td colspan="2">
            <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
        </td>
    </tr>
       </table>
    </div>
    </form>
</body>
</html>





CODE: edit-friend.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 edit_friend : System.Web.UI.Page
{
    FriendDataClassesDataContext db = new FriendDataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if(!IsPostBack)
        {
            var FriendID = Convert.ToString(Request.QueryString["frndid"]);
            var FriendDetail = (from a in db.dbFriends
                                where a.FriendID == Convert.ToInt32(FriendID)
                                select a).FirstOrDefault();

            if (FriendDetail != null)
            {
                txtFriendName.Text = FriendDetail.FriendName;
                txtMobile.Text = FriendDetail.Mobile;
            }
        }
        

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        var FriendID = Convert.ToString(Request.QueryString["frndid"]);

        var FriendDetail = (from a in db.dbFriends
                            where a.FriendID == Convert.ToInt32(FriendID)
                            select a).FirstOrDefault();

        if (FriendDetail != null)
        {
            FriendDetail.FriendName = txtFriendName.Text;
            FriendDetail.Mobile = txtMobile.Text;
            db.SubmitChanges();
        }
    }
}

Radio Button Asp.Net WebForm | radio button in asp.net c# for gender | R...




CODE: radio-button-sample.aspx   

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="radio-button-sample.aspx.cs" Inherits="radio_button_sample" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButton ID="rbtnMale" runat="server" Text="Male" GroupName="gender"  />
        <asp:RadioButton ID="rbtnFemale" runat="server" Text="Female" GroupName="gender"  />
    </div>
        <br />
        <br />
        <asp:Button ID="btnSubmit" Text="Submit" runat="server"  OnClick="btnSubmit_Click"/>
        <br />
        <br />
        <asp:Label ID="lblMsg" runat="server"></asp:Label>
    </form>
</body>
</html>



CODE:  radio-button-sample.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 radio_button_sample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (rbtnMale.Checked == true)
        {
            lblMsg.Text = "You selected  gender " + rbtnMale.Text;
        }
        else
        {
            lblMsg.Text = "You selected  gender " + rbtnFemale.Text;
        }
    }
}



table list using linq to sql | Index Page Linq To Sql | display records ...






 Now copy following code and enjoy.

CODE : Friend-List.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Friend-List.aspx.cs" Inherits="Friend_List" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Friend List</h1>
        <a  href="Default.aspx">New Friend</a>
       <asp:GridView ID="gvFriend" runat="server" AutoGenerateColumns="false">
            <Columns>
                 <asp:TemplateField HeaderText="Sr.No">
                                    <ItemTemplate>
                                        <%# Container.DataItemIndex + 1%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                <asp:BoundField DataField="FriendName" HeaderText="Friend Name" />
                <asp:BoundField DataField="Mobile"  HeaderText="Mobile" />
                <asp:TemplateField HeaderText ="Edit" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                     <a href='edit-friend.aspx?frndid=<%#Eval("FriendID")%>'>Edit</a>
                        </ItemTemplate>
                </asp:TemplateField>
              <asp:TemplateField HeaderText ="Delete" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                     <a href='delete-friend.aspx?frndid=<%#Eval("FriendID")%>'>Delete</a>
                        </ItemTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>





CODE -- Friend-List.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 Friend_List : System.Web.UI.Page
{
    FriendDataClassesDataContext db = new FriendDataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        var FrndList = (from a in db.dbFriends select a).ToList();
        gvFriend.DataSource = FrndList;
        gvFriend.DataBind();
    }
}




















I provide Asp.Net WebForm, MVC, Core training. You can me contact for further guidance.

Mobile : 9869166077


Email :  manojbkalla@hotmail.com // mr.manojbkalla@gmail.com





ReactJs training, Angular Training in Malad, Kandivali, Borivali, Andheri, Bandra, Juhu, Marine Line, Kalbadevi, Virar, Vasai, Dadar, Mumbai.

Provide all BCA, MCA Training online or offline.

YCMOU university courses.





Sunday 18 April 2021

linq to sql insert record, linq to sql add record,, linq to sql insert...




Step by step guide:

1. Create project .

2. Add a aspx page --- default.aspx

3. Add LINQ TO SQL class. Visual Studio asked to create in APP_CODE 
folder.

4. VIEW option click on SERVER EXPLORER or press [CTRL +W + L]

5. Server Explorer you can see now.

6. On Server Explorer Right click   DATA CONNECTIONS --->Add 
Connections.

7. As you connection established, now you click on Database you had added in connection then click on TABLES expand it this section.

8. Switch to Solution Explorer double click on DBML file which is located inside APP_CODE .

9. Drag your table on the DBML canvas.

10. As you completed drag operation you can see Web.Config file auto updated with CONNECTION STRING.

Now copy following code and enjoy.

I provide Asp.Net WebForm, MVC, Core training. You can me contact for further guidance.

Mobile : 9869166077
Email :  manojbkalla@hotmail.com // mr.manojbkalla@gmail.com


CODE:   Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       
<table>
           <tr>
               <td>
                   Friend Name
               </td>
               <td>
                   <asp:TextBox ID="txtFriendName" runat="server"></asp:TextBox>
               </td>
           </tr>

           <tr>
               <td>
                   Mobile 
               </td>
               <td>
                   <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
               </td>
           </tr>
    <tr>
        <td colspan="2">
            <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
        </td>
    </tr>
       </table>

    </div>
    </form>
</body>
</html>





CODE :    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 _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        FriendDataClassesDataContext db = new FriendDataClassesDataContext();
        dbFriend newfriend = new dbFriend();
        newfriend.FriendName = txtFriendName.Text;
        newfriend.Mobile = txtMobile.Text;
        db.dbFriends.InsertOnSubmit(newfriend);
        db.SubmitChanges();
    }
}






CODE :  web.config
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  
  <connectionStrings>
    <add name="dbLearningConnectionString" connectionString="Data Source=DESKTOP-IJ20K2E\SQLEXPRESS;Initial Catalog=dbLearning;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>
</configuration>



CODE:  SQL SCRIPT TO CREATE TABLE

/****** Object:  Table [dbo].[dbFriends]    Script Date: 24-04-2021 21:01:20 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[dbFriends](
[FriendID] [int] IDENTITY(1,1) NOT NULL,
[FriendName] [varchar](100) NULL,
[Mobile] [varchar](50) NULL,
 CONSTRAINT [PK_dbFriends] PRIMARY KEY CLUSTERED 
(
[FriendID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO


Introduction of Solution Explorer, What is Solution Explorer in Visual S...