Wednesday, 15 May 2013

Create DLL and Using Website Dll in asp.net

Create DLL and Using Website Dll in asp.net


New Project Create :

  Start --->New Project --- > Class Library



 //SampleDLL:

  namespace SampleDLL
   {
 //Class Create
     public class Sample
      {
        public int Sum(int a, int b)
        {
            int c;
            c = a + b;
            return c;
        }
        
        }
    }

Website Add DLL:

 Start --->New Web Site 

 DLL Add Website:

   Solution (Right Click) --->Add Refrence --- >Browse 
              --- >(DLL Folder Select)bin -- >Debug--- >
                                    SamplaeDLL.dll(.dll Select)

                    












aspx:
<div align="center">
    <asp:Label ID="lblA" runat="server" Text="a Value"></asp:Label>
        <asp:TextBox ID="txtA" runat="server">
       </asp:TextBox>
           <br />
           <br />
    <asp:Label ID="lblB" runat="server" Text="b Value"></asp:Label>
         <asp:TextBox ID="txtB" runat="server">
          </asp:TextBox>
    <br />
    <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button  ID="btnAdd" runat="server" Text="Add"    
       onclick="btnAdd_Click"/>
    <asp:Label ID="lblVal" runat="server"></asp:Label>
</div>

aspx:CS :


 protected void btnAdd_Click(object sender, EventArgs e)
    {
        int i, j, k;
 //Object Crteate DLL
 //SampleDLL dllName
 //Sample ClassName
        SampleDLL.Sample objSam = new SampleDLL.Sample();

        i =Convert.ToInt32(txtA.Text);
        j = Convert.ToInt32(txtB.Text);
//Sample Value(a,b)
        k= objSam.Sum(i, j);
        lblVal.Text = k.ToString();
    }

Screen:










No comments:

Post a Comment