shake demo

Click to shake the box.

Friday, 21 November 2014

C# Evaluate Expression- Mathematical calculation

<asp:TextBox ID="txtEquation" runat="server" MaxLength="50"></asp:TextBox>
                    <asp:Button ID="calculate" runat="server" Text="Calculate" OnClick="calculate_Click" />
                    <asp:Label ID="lblResult" runat="server" Text="0"></asp:Label>

 private object EvaluateExpression(string eqn)
        {
            DataTable dt = new DataTable();
            var result = dt.Compute(eqn, string.Empty);
            return result;
        }

        protected void calculate_Click(object sender, EventArgs e)
        {
            try
            {
                string result = Convert.ToString(EvaluateExpression(txtEquation.Text.Trim()));
                lblResult.Text = "Result: " + String.Format(result, "#.##");
                lblResult.ForeColor = Color.Green;
            }
            catch (Exception ex)
            {
                lblResult.Text = "Oops!! error occured: " + ex.Message.ToString();
                lblResult.ForeColor = Color.Red;
            }
        }

OutPut is:


Disable Browser Back Button

// Add below js code on master page or any .js file
<%-- Code for browswer back button disable start from here --%>
   
    <script type="text/javascript" language="javascript">

        function changeHashOnLoad() {
            window.location.href += '#';
            setTimeout('changeHashAgain()', '50');
        } 12438.00

        function changeHashAgain() {
            window.location.href += '1';
        }

        var storedHash = window.location.hash;
        window.setInterval(function () {
            //          if (window.location.hash != storedHash) {
            window.onhashchange = function () { window.location.hash = storedHash; }
            window.location.hash = storedHash;

        }, 50);
        window.onload = changeHashOnLoad;
        window.location.hash = "no-back-button";
        window.location.hash = "Again-no-back-button"; //for google chrome
        // window.onhashchange = function () { window.location.hash = "no-back-button"; }
        window.history.forward(1);
        history.go(1);
    </script>
    <%-- end Code for browswer back button disable --%>