Thursday 30 October 2014

How not to validate HTML5 text box with required attribute

Here I am explain,How not to validate HTML5 text box with required attribute


<form>
    <input type="text" name="firstname" required />
    <input type="number" min="1" max="100" required />
    <input type="submit">Add</input>
    <input type="submit" formnovalidate>Cancel</input>

</form>

Disable resize for ASP.Net Multiline TextBox

Here I am example, how to disable resize i.e. prevent resizing of the ASP.Net Multiline TextBox due to the resize grip in the bottom right corner using CSS3.
This works in all newer browsers such as Internet Explorer IE, Mozilla FireFox and Google Chrome


You can either do it by setting it directly in the style attribute.

Source 1:

<asp:TextBox ID="TextBox1" runat="server" TextMode = "MultiLine" style = "resize:none"></asp:TextBox>

Or make use of the CSS style sheet. If you want to disable resize for all the ASP.Net Multiline TextBoxes

Source 2:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        textarea
        {
            resize: none;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox2" runat="server" TextMode = "MultiLine"></asp:TextBox>
    </form>
</body>
</html>

Wednesday 29 October 2014

The return types for the following stored procedures could not be detected



Error: Unknown Return Type, The return types for the following stored procedures could not be detected….(LINQ).

Error: Unknown Return Type, The return types for the following stored procedures could not be detected…..

Error:
The return types for the following stored procedures could not be detected. Set the return type for each stored procedure in the Properties window.

Situations
This error usually comes when you are trying to add your Stored Procedure into DBML (LINQ) file.

Cause
This problem occurs whenever the designer cannot figure out the return type of the SP. This usually happens when the stored procedure has multiple results or uses a temp table. The SQL Server feature that attempts to derive the Meta data of the function reports no columns for the result shape, so the designer defaults to thinking it only has the single int return value.

Solutions
· The one way to get these types of stored procedures to work is to edit DBML by hand or write your own method signature for the procedure in a partial class To Handle multiple record set return from stored procedure by LINQ see the link here.

· The second way is to avoid using #temp Table in your stored procedure, instead of you can use Table type variable like below (@TempTable)
Ex:
DECLARE @TempTable TABLE
(
AttributeID INT,
Value NVARCHAR(200)
)

INSERT INTO @TempTable Select * from Attribute
OR
--Execute SP and insert results into @TempTable
INSERT INTO @TempTable Exec GetAttribute @Id
You can do all operation which you was doing with #Temp table like Join, Insert, Select etc.

Tuesday 28 October 2014

jQuery to calculate Running Total of Asp.Net Textbox values and show in Label or TextBox control

Introduction: In this article i am going to explain how to get running sum of all the asp.net textbox values using jQuery and display in Label or Textbox control.



Description:  While working on asp.net project I got the requirement to implement the functionality of getting running total of item price in label or textbox as soon as they are entered. Whenever we enter the price of any item in the textbox, total price gets updated in the label reflecting the Total Price as you can see in the demo image above.

Source 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 id="Head1" runat="server">
    <title></title>
    <script src="//code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //Iterate through each Textbox and add keyup event handler
            $(".clsTxtToCalculate").each(function () {
                $(this).keyup(function () {
                    //Initialize total to 0
                    var total = 0;
                    $(".clsTxtToCalculate").each(function () {
                        // Sum only if the text entered is number and greater than 0
                        if (!isNaN(this.value) && this.value.length != 0) {
                            total += parseFloat(this.value);
                        }
                    });
                    //Assign the total to label
                    //.toFixed() method will roundoff the final sum to 2 decimal places
                    $('#<%=lblTotalPrice.ClientID %>').html(total.toFixed(2));
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fieldset style="width: 315px;">
            <legend>Running Total of all TextBoxes</legend>
            <table border="1px" cellpadding="5" style="border-collapse: collapse;">
                <tr style="text-align: left;">
                    <th>
                        No.</hd>
                        <th>
                            Item
                        </th>
                        <th>
                            Price
                        </th>
                </tr>
                <tr>
                    <td>
                        1
                    </td>
                    <td>
                        Milk:
                    </td>
                    <td>
                        <asp:TextBox ID="txtMilk" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        2
                    </td>
                    <td>
                        Bread:
                    </td>
                    <td>
                        <asp:TextBox ID="txtBread" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        3
                    </td>
                    <td>
                        Noodles:
                    </td>
                    <td>
                        <asp:TextBox ID="txtNoodles" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        4
                    </td>
                    <td>
                        Cheese:
                    </td>
                    <td>
                        <asp:TextBox ID="txtCheese" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <b>Total Price</b>
                    </td>
                    <td>
                        <asp:Label ID="lblTotalPrice" runat="server"></asp:Label>
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>
    </form>
</body>

</html> 

Note: If you want to show the running total in TextBox instead of label then replace

<asp:Label ID="lblTotalPrice" runat="server"></asp:Label>
 With
<asp:TextBox ID="txtTotalPrice" runat="server"></asp:TextBox>

And $('#<%=lblTotalPrice.ClientID %>').html(total.toFixed(2));
With
$('#<%=txtTotalPrice.ClientID %>').val(total.toFixed(2));