Friday, June 17, 2016

update controls outside updatepanel c#

In this article, I am going to explain how to update Control value or any other ASP. net control which reside out side update panel.

Let's take a example, suppose I have a button inside update panel and click on that button I want to assign some value in textbox.

Here the aspx Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scmain" runat="server"></asp:ScriptManager>
 
    <asp:UpdatePanel ID="upmain" runat="server">
    <ContentTemplate>
     <fieldset>
    <legend>Button Inside Update Panel</legend>
    <asp:Button ID="btnUpdateValue" runat="server" Text="UpdateValue"
             onclick="btnUpdateValue_Click" />
    </fieldset>
    </ContentTemplate>
    </asp:UpdatePanel>
 
     <asp:UpdatePanel ID="uptextbox" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <fieldset>
    <legend>Out Side TextBox of Update Panal</legend>
    <asp:TextBox ID="txtvalue" runat="server"></asp:TextBox>
    </fieldset>
    </ContentTemplate>
    </asp:UpdatePanel>
 
    </form>
</body>
</html>

Here the aspx.cs Code

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 btnUpdateValue_Click(object sender, EventArgs e)
    {
        txtvalue.Text = "Verified";
        uptextbox.Update();
    }
}

Output




Saturday, June 11, 2016

Write a program to find GCD of 2 numbers in C#.NET



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main()
        {
            int i, i1;

            Console.WriteLine("Enter 2 numbers to find GCD");
            i = int.Parse(Console.ReadLine());
            i1 = int.Parse(Console.ReadLine());

            int num, num1;
      
            if (i > i1)
            {
                num = i;
                num1 = i1;
            }
            else
            {
                num = i1;
                num1 = i;
            }
            int output = gcd(num, num1);
            Console.WriteLine("The GCD of {0} and {1} is {2}", i, i1, output);
            Console.Read();
        }

        private static int gcd(int num, int num1)
        {
            int rem = 5;
            while (num1 > 0)
            {
                rem = num % num1;
                if (rem == 0)
                    return num1;
                num = num1;
                num1 = rem;

            }

            return num;

        }
    }
}

Output : 



Wednesday, June 8, 2016

Write a Program to convert Decimal to Binary in C#.NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication16
{
    class Program
    {
        static void Main()
        {
            int num;
            Console.Write("Enter a Number : ");
            num = int.Parse(Console.ReadLine());
            int q;
 
            string rem = "";
 
            while (num >= 1)
            {
                q = num / 2;
                rem += (num % 2).ToString();
                num = q;
            }
 
 
            string b = "";
            for (int i = rem.Length - 1; i >= 0; i--)
            {
                b = b + rem[i];
 
            }
 
            Console.WriteLine("The Binary num of given number is {0}", b);
 
 
            Console.Read();
 
        }
    }

}

Output :

Tuesday, June 7, 2016

Write program to find LCM of 2 numbers in C# .NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication15
{
    public class LCM
    {
        public static int dLCM(int a, int b)
        {
            int n1, n2;
            if (a > b)
            {
                n1 = a; n2 = b;
            }
            else
            {
                n1 = b; n2 = a;
            }
 
            for (int i = 1; i <= n2; i++)
            {
                if ((n1 * i) % n2 == 0)
                {
                    return i * n1;
                }
            }
            return n2;
        }
 
        public static void Main(String[] args)
        {
            int n01, n02;
 
            Console.WriteLine("Enter 2 numbers :");
 
            n01 = int.Parse(Console.ReadLine());
            n02 = int.Parse(Console.ReadLine());
 
            int l = dLCM(n01, n02);
 
            Console.WriteLine("LCM of {0} and {1} is {2}", n01, n02, l);
            Console.Read();
        }
    }

}

Output : 

Monday, June 6, 2016

sql server query shortcuts

In daily life developer needs to execute different type of sql query , Lets suppose that you want to fetch data from a table so for that the query will be "select * from table-name", As per on developer terms they executes selcet * query many times on daily basis. So for daily use these shortcuts will come handy to you.
 

Click on "Option" menu, Click on "Keyboard" menu item.



Click On "OK"



Now , write the table name, select that table name and press "ctrl+3" you employee table return data


You can create many of shortcut as per your need.

Write a program to reverse a string in C# .Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication14
{
    class StringReverse
    {
        static void Main()
        {
 
            string S, rev = "";
            Console.Write("Enter A String ");
            S = Console.ReadLine();
 
            for (int i = S.Length - 1; i >= 0; i--)
            {
 
                rev = rev + S[i];
            }
 
            Console.WriteLine("Reverse  String  Is  {0}", rev);
            Console.ReadLine();
        }
    }

}

Output : 

Monday, May 23, 2016

Remember me on checkbox checked on login page in asp.net

In this article, I am going to explain how to implement  "Remember Me" functionality for next time in ASP. net c#.

Copy the aspx code in your aspx page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RememberMe.aspx.cs" Inherits="RememberMe" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   
    <fieldset>
    <legend>User Login</legend>
    <table>
    <tr>
    <td>User Name: </td>
    <td><asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><span style="color:Red">*</span>
    <asp:RequiredFieldValidator ID="rfvtxtUserName" ValidationGroup="M" Display="None"
    ControlToValidate="txtUserName" runat="server" ErrorMessage="Please enter User Name"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>Password: </td>
    <td><asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox><span style="color:Red">*</span>
     <asp:RequiredFieldValidator ID="rfvtxtPassword" ValidationGroup="M" Display="None"
    ControlToValidate="txtPassword" runat="server" ErrorMessage="Please enter Password"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td><asp:Button ID="btnLogin" runat="server" Text="Login" onclick="btnLogin_Click" ValidationGroup="M"/>
    <asp:CheckBox ID="chkNextTime" runat="server" Text="Remember Me Next Time" />
    </td>
    </tr>
 
    </table>
    </fieldset>
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="M"
        ShowMessageBox="true" ShowSummary="false" HeaderText="following error occurs"
        ForeColor="Red" Font-Bold="true" />
    </form>
</body>
</html>

Now,Copy the aspx,cs code in your cs page.

using System;
 
public partial class RememberMe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null)
            {
                txtUserName.Text = Request.Cookies["UserName"].Value;
                txtPassword.Attributes["value"] = Request.Cookies["Password"].Value;
            }
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (chkNextTime.Checked)
        {
            Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30);
            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
        }
        else
        {
            Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
 
        }
        Response.Cookies["UserName"].Value = txtUserName.Text.Trim();
        Response.Cookies["Password"].Value = txtPassword.Text.Trim();
    }
}


OutPut: