Pages

Thursday 28 March 2013

Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: The file '/Account/Site.master' does not exist.

 

Server Error in '/Account' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The file '/Account/Site.master' does not exist.

Source Error:

Line 1:  <%@ Page Title="Register" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"Line 2:      CodeBehind="Register.aspx.cs" Inherits="Tranzhop.Account.Register" %>
Line 3:  

Source File: /account/register.aspx    Line: 1


Solution: However, this issue turned out to be an IIS7 issue. The error message I described arose out of the distinction made in IIS7 between a "virtual directory" and an "application" (I don't know if such a distinction existed in IIS6). To fix this error, I opened IIS7, right-clicked on the virtual directory folder for this site, and selected "Convert to Application." I then refreshed the browser, and the error went away.

Wednesday 20 March 2013

Handling Empty Data in an ASP.NET Repeater control

The GridView has an EmptyDataText property or the <EmptyDataTemplate> that lets us handle EmptyData. However the Repeater has no such property or template. In this short article, we will see how to adopt a simple technique to handle empty data in an ASP.NET Repeater control without creating a custom control.
Drag and drop a Repeater and a SQLDataSource control to the page. Bind the Repeater to the SQLDataSource as you usually do
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"            
    onitemdatabound="Repeater1_ItemDataBound">
 <HeaderTemplate>
    <table border="1" cellpadding="3" cellspacing="3">
    <tr bgcolor="blue">
    <td><b>CustomerID</b>
    </td>
    <td><b>CompanyName</b>
    </td>
    <td><b>ContactName</b>
    </td>
    <td><b>ContactTitle</b></td>
    </tr>
</HeaderTemplate>
 <ItemTemplate>
     <tr>
     <td>
        <%#DataBinder.Eval(Container.DataItem, "CustomerID")%>
     </td>
     <td>
        <%#DataBinder.Eval(Container.DataItem, "CompanyName")%>   
     </td>
     <td>
        <%#DataBinder.Eval(Container.DataItem, "ContactName")%>   
     </td>
     <td>
        <%#DataBinder.Eval(Container.DataItem, "ContactTitle")%>   
     </td>
     </tr>
 </ItemTemplate>
 <FooterTemplate>
 </table>           
 </FooterTemplate>
 
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName],
    [ContactTitle], [Address] FROM [Customers] " >
</asp:SqlDataSource>
</div>
In your web.config, add a connection string as shown below:
 
      <connectionStrings>
            <add name="NorthwindConnectionString" connectionString="Data Source =(local);Integrated Security = SSPI; Initial Catalog=Northwind;"/>
      </connectionStrings>
 
If you run the application, the repeater would display the data from the database. Now change the query so that it returns empty data.
SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address] FROM [Customers] WHERE CUSTOMERID=’XYZ’
 
On running the application, you would see the following:
Empty Data
Now this display is not elegant enough to inform the user that there is no data, right? So let us see how to display a message in the Repeater control when there is no data present.
In the <FooterTemplate>, add a Label with some empty data text and set its visible property to false.
<FooterTemplate>
 <tr>
 <td>
 <asp:Label ID="lblEmptyData"
        Text="No Data To Display" runat="server" Visible="false">
 </asp:Label>
 </td>
 </tr>
 </table>           
 </FooterTemplate>
Now add an ItemDataBound event to the Repeater
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"            
    onitemdatabound="Repeater1_ItemDataBound">
In the code behind, write the following code:
C#
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (Repeater1.Items.Count < 1)
        {
            if (e.Item.ItemType == ListItemType.Footer)
            {
                Label lblFooter = (Label)e.Item.FindControl("lblEmptyData");
                lblFooter.Visible = true;
            }
        }
    }
VB.NET
      Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
            If Repeater1.Items.Count < 1 Then
                  If e.Item.ItemType = ListItemType.Footer Then
                        Dim lblFooter As Label = CType(e.Item.FindControl("lblEmptyData"), Label)
                        lblFooter.Visible = True
                  End If
            End If
      End Sub
The code checks if the Repeater has items in it. If the items count is less than 1, the code uses the FindControl() to locate the label and set it to visible.
On running the application again, you get to see the message 'No Data To Display' as shown in the screenshot below. This is certainly more user friendly than letting the user wonder why the data was not displayed at the first place.
Empty Data Message

Wednesday 13 March 2013

To remove or replace multiple special character from string using sql queries.

CREATE FUNCTION [FN_REMOVE_SPECIAL_CHARACTER] (  
 @INPUT_STRING varchar(300))
RETURNS VARCHAR(300)
AS 
BEGIN
 
--declare @testString varchar(100),
DECLARE @NEWSTRING VARCHAR(100) 
-- set @teststring = '@san?poojari(darsh)'
 SET @NEWSTRING = @INPUT_STRING ; 
With SPECIAL_CHARACTER as
(
SELECT '>' as item
UNION ALL 
SELECT '<' as item
UNION ALL 
SELECT '(' as item
UNION ALL 
SELECT ')' as item
UNION ALL 
SELECT '!' as item
UNION ALL 
SELECT '?' as item
UNION ALL 
SELECT '@' as item
UNION ALL 
SELECT '*' as item
UNION ALL 
SELECT '%' as item
UNION ALL 
SELECT '$' as item
 )
SELECT @NEWSTRING = Replace(@NEWSTRING, ITEM, '') FROM SPECIAL_CHARACTER  
return @NEWSTRING 
END 
 
select dbo.[FN_REMOVE_SPECIAL_CHARACTER] ('@s()antosh')
 
 
CREATE FUNCTION [dbo].[udfGetCharacters](@inputString VARCHAR(MAX), @validChars VARCHAR(100))
RETURNS VARCHAR(500) AS
BEGIN
 
 WHILE @inputString like '%[^' + @validChars + ']%'
  SELECT @inputString = REPLACE(@inputString,SUBSTRING(@inputString,PATINDEX('%[^' + @validChars + ']%',@inputString),1),'')

 RETURN @inputString
END
 
--Usage of the function
select [dbo].udfGetCharacters('utkarsh puranik`s blog' ,'0-9a-z ')

--output
utkarsh puraniks blog