Friday, May 9, 2014

Working With Encryption an Decryption

Design the Form as Following

<div>
<asp:TextBox ID="txtEncrypt" runat="server"></asp:TextBox>
 <asp:Button ID="btnEncrypt" runat="server" Text="Encrypt" OnClick="btnEncrypt_Click" />
 <asp:TextBox ID="txtDencrypt" runat="server"></asp:TextBox>
 <asp:Button ID="btnDencrpt" runat="server" Text="Dencrypt" OnClick="btnDencrpt_Click" />

</div>




Add New Item and a add a new class File with the name
EncryptDencrypt.cs


Add the following Namespaces

using System.Security.Cryptography;
using System.Text;

write the following code


public class EncryptDencrypt
    {

    TripleDESCryptoServiceProvider tdc;
    MD5CryptoServiceProvider mdcs;
     public EncryptDencrypt()
     {
          tdc = new TripleDESCryptoServiceProvider();
          mdcs = new MD5CryptoServiceProvider();
     }
  


    public string Encryption(string Data)
    {
    Byte[] eNC_data = ASCIIEncoding.ASCII.GetBytes(Data);
    string eNC_str = Convert.ToBase64String(eNC_data);
    return eNC_str;
    }

    public string Decryption(string Data)
    {
    Byte[] dEC_data = Convert.FromBase64String(Data);
    string dEC_Str =ASCIIEncoding.ASCII.GetString(dEC_data);
    return dEC_Str;
    }

 }





Write the following code in .cs page


protected void btnEncrypt_Click(object sender, EventArgs e)
    {
        if(!string.IsNullOrEmpty(txtEncrypt.Text))
        {
            EncryptDencrypt objency=new EncryptDencrypt();
            txtDencrypt.Text=objency.Encryption(txtEncrypt.Text);
        }
       
    }




protected void btnDencrpt_Click(object sender, EventArgs e)
    {
      if (!string.IsNullOrEmpty(txtDencrypt.Text))
      {
         EncryptDencrypt objdency = new EncryptDencrypt();
            txtEncrypt.Text = objdency.Decryption(txtDencrypt.Text);
        }
    }




Enter the text and click on Encrypt Button




Next Enter any Dencrpt Text and Click on Dencrpt and see the output.


Grid View with Text Box

Design the form as shown below

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<asp:TextBox ID="txtFilterby" runat="server" OnKeyUp="f1()" onfocus="SetFocusEnd(this)" Width="325px"></asp:TextBox>
<asp:UpdateProgress ID="UpdateProgress2" AssociatedUpdatePanelID="updPanelAllDocs" runat="server">
<ProgressTemplate>
<img src="images/loading.gif" alt="Loading..." height="14px" width="14" style="border: 1px solid white!important; margin-top: 4px;" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="updPanelAllDocs" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="BranchName" DataField="BranchName" ShowHeader="true" />
<asp:BoundField HeaderText="AmountRequested" DataField="AmountRequested" ShowHeader="true" />
<asp:BoundField HeaderText="FundingDate" DataField="FundingDate" ShowHeader="true" />
<asp:BoundField HeaderText="ProductCode" DataField="ProductCode" ShowHeader="true" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>

</form>

Default.aspx





Write the following JavaScript code in the Page.

<script type="text/javascript">
function f1() {

__doPostBack('<%= this.updPanelAllDocs.ClientID %>', '');
}
function SetFocusEnd(TB) {
if (TB.createTextRange) {
var FieldRange = TB.createTextRange();
FieldRange.moveStart('character', TB.value.length);
FieldRange.collapse(); FieldRange.select();
}
}
</script>


Write the following code in Default.aspx.cs






Code in Default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStrings"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from sampledata";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
ViewState["AvailableProducts"] = ds;
con.Close();
}

else
{
DataView dvData=new DataView();
DataSet ds = new DataSet();
if (ViewState["AvailableProducts"] != null)
{
if (txtFilterby.Text.Length > 0)
{
DataSet dsTemp = (DataSet)ViewState["AvailableProducts"];
if (dsTemp != null && dsTemp.Tables.Count > 0)
{
dvData = new DataView(dsTemp.Tables[0]);
dvData.RowFilter = "BranchName like '%" + txtFilterby.Text + "%'" + "or ProductCode like '%" + txtFilterby.Text + "%'";
DataTable  dtAllDocs = dvData.ToTable();
ds.Tables.Add(dtAllDocs);
ViewState["dvTableFilter"] = ds;
}
if (dvData != null && dvData.Count > 0)
{
dvData.Sort = "AmountApproved ASC";
GridView1.DataSource = dvData;
GridView1.DataBind();
}
else
{
DataTable dtTable = new DataTable();
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
GridView1.DataSource = ds;
GridView1.DataBind();
int columncount = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
GridView1.Rows[0].Cells[0].Text = "No Documents Found";
}
}
}
}
}



Working with Iframes

Working with I Frames.

Design the Form as shown Below

Default.aspx
<div>
<iframe  id="frame1" runat="server"width="400"height="400"></iframe>

</div>


Default.aspx.cs

protected void Page_Load(object sender, EventArgse)
{
frame1.Attributes["src"] = "http://www.w3cschools.com";
}


Output:



Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...