Search This Blog

Showing posts with label ASP. Show all posts
Showing posts with label ASP. Show all posts

Monday, May 21, 2012

C# MVC3 Razor


I've been onto razor lately, and I must admit I am new to this approach. Using the tutorial working with data set I wanted to populate the data from database to the table with alternating row style applied. The output would be same as below. Doing it manually is quite easy. But, what if our data is coming from the database? How can we achieve this? There are quite a number of ways to achieved it view it here. But I wanted to have a simple approach and that is using CSS. Fortunately we can do it in pure CSS
            #customers tr.alt:nth-child(even) td
            {
            color:#000000;
            background-color:#EAF2D3;
            }
 Modifying the code in tutorial  with code below we can attain our objective of having alternating row style in table.

<style type="text/css">
            #customers
            {
            font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
            width:100%;
            border-collapse:collapse;
            }
            #customers td, #customers th
            {
            font-size:1em;
            border:1px solid #98bf21;
            padding:3px 7px 2px 7px;
            }
            #customers th
            {
            font-size:1.1em;
            text-align:left;
            padding-top:5px;
            padding-bottom:4px;
            background-color:#A7C942;
            color:#ffffff;
            }
            #customers tr.alt:nth-child(even) td
            {
            color:#000000;
            background-color:#EAF2D3;
            }
</style>

<body>
        <a href="~/InsertProducts">Insert Products</a>
        <a href="~/EditProducts">Edit Products</a>
        <a href="~/ListProductsForDelete">Delete Products</a>
        <h1>Small Bakery Products</h1>
        <table id ="customers">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Product</th> 
                    <th >Description</th>
                    <th >Product Description</th>
                    <th>Price</th>
                </tr>    
            </thead>
            <tbody>
                @foreach(var row in db.Query(selectQueryString)){
                <tr class="alt">
                    <td><a href="@Href("~/UpdateProducts", row.Id)">Edit</a></td>
                    <td><a href="@Href("~/DeleteProduct", row.Id)">Delete</a></td>
                    <td>@row.Name</td>
                    <td>@row.Description</td>
                    <td>@row.Price</td>
                </tr>
                }
            </tbody>
        </table>     
        <br />
</body>


 ID Product Product Description Prices
1 Carrot Cake A scrumptious mini-carrot cake encrusted with sliced almonds 8.99
2 Lemon Tart A delicious lemon tart with fresh meringue cooked to perfection 9.99
3 Cupcakes Delectable vanilla and chocolate cupcakes 5.99
4 Bread Fresh baked French-style bread 1.49
5 Pear Tart A glazed pear tart topped with sliced almonds and a dash of cinnamon 5.99
6 Chocolate Cake Rich chocolate frosting cover this chocolate lover’s dream. 8.99
7


8


9


10


Thursday, February 16, 2012

Server Error in '/Application Name' Application

Today, I encountered error Server Error in '/Application Name' Application.
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Ideally in web application when using stored procedure in collating data the processing
time for stored should be not greater than 1 second only. However  in my case the processing
time was 34 sec that's 34 times slower than the ideal time. In displaying details to the users I used the N-tier approach and used stored procedure in querying data. But my stored procedure is too slow, as mentioned in generating 128923 rows  it took 34seconds to processed. Increasing the timeout period can temporarily cure the problem but it is not a proactive approach. Instead I make use of temporary tables during run time and scaling my database - proper indexing.

Friday, December 16, 2011

JQuery Date

JQuery library is one of the most popular javascript library today. Its an open source library and one can customize it according to users needs. One of the very popular and widely used function is the date picker functionality of jquery. In this post I will implement the datepicker using jquery in asp page using master page and normal asp page.

Using normal Page is quite simple and start forward.
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>JQuery Testing</title>
        <link rel = "Stylesheet" href ="../jquery-ui-1.8.13.custom/development-bundle/demos/demos.css" />
        <link rel = "Stylesheet" href ="../jquery-ui-1.8.13.custom/development-bundle/themes/base/jquery.ui.all.css" />

        <script src="../Scripts/jquery-1.6.1.js" type="text/javascript"></script>
        <script src="../Scripts/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            $("#<%= txtFoo.ClientID  %>").datepicker();
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input runat="server" type="text" id="txtFoo"  />

    </form>
</body>
</html>
JQuery in Master Page is quite simple too: Below is the code for our master page. This is inside head tag.
<link rel = "Stylesheet" href ="../jquery-ui-1.8.13.custom/development-bundle/demos/demos.css" />
<link rel = "Stylesheet" href ="../jquery-ui-1.8.13.custom/development-bundle/themes/base/jquery.ui.all.css" />
   
<script language="javascript" src="script.js"> </script>

<script src="../Scripts/jquery-1.6.1.js" type="text/javascript"></script>
<script src="../Scripts/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>
 In our content page we will place this code.
<asp:Content ID="Content1" ContentPlaceHolderID="maincontent" Runat="Server">
    
    <script type="text/javascript">
        $(function () {

            $("#<%= txtFoo.ClientID  %>").datepicker();

        });
    </script>
    <div id ="reportresults">
        <input runat="server" type="text" id="txtFoo"/>
    </div> 
</asp:Content> 
Happy coding!