Tuesday, June 19, 2007

HTML printing with custom page format

You may always noticed that whenever we try to print a web page with a click on "Print Friendly" or "Print" or "Print Preview", the page will open up a pop up window with a different simple layout with no extravaganzas, say buttons, advertisements, etc.

This is simply achieved with CSS. The solution is as follows.

Defined two sets of CSS for the page targeting "Print" and "Screen". See the example below.

<style type="text/css">
@media screen{
body {color:Red; }
td{font-size:14px;}
.noprint{display:block !important;}

}

@media print {
body {fcolor:Blue;}
td{font-size:7px;}
.noprint{display:none;}
}
</style>

and the page is

<form id="form1" runat="server">
<div style="text-align: center;">
<table id="tblParent" style="width: 90%">
<tr class="noprint">
<td>
This is just a demonstration of how to make HTML printing</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr class="noprint">
<td style="text-align: right">
<a href="#" onclick="window.print()">Print</a>  <a href="#" onclick="window.close()">Close</a>
</td>
</tr>
<tr>
<th>
Employee Informations</th>
</tr>
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table id="tblEmployee" style="width: 100%">
<tr>
<td style="width: 5%;">
</td>
<td style="width: 30%;">
</td>
<td style="width: 5%;">
</td>
<td style="width: 60%;">
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
Last Name</td>
<td>
:</td>
<td align="left">
<%# Eval("LastName") %>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
First Name</td>
<td>
:</td>
<td align="left">
<%# Eval("firstname") %>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
Title</td>
<td>
:</td>
<td align="left">
<%# Eval("title") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</div>
</form>

Here the section of the page with class .noprint is displayed while displaying on the "screen" and hidden while printing, say buttons and other items


-::-

Sunday, June 17, 2007

URL rewriting in ASP.Net 2.0! Purpose and how to?

URL rewriting is the process of intercepting an incoming Web request and automatically redirecting it to a different URL.

Creating data-driven ASP.NET websites often results in a single Web page that displays a subset of the database's data based on querystring parameters. For example, in designing an e-commerce site, one of your tasks would be to allow users to browse through the products for sale. To facilitate this, you might create a page called displayCategory.aspx that would display the products for a given category. The category's products to view would be specified by a querystring parameter. That is, if the user wanted to browse the Widgets for sale, and all Widgets had a had a CategoryID of 5, the user would visit: http://yousite.com/displayCategory.aspx?CategoryID=5.
There are two downsides to creating a website with such URLs. First, from the end user's perspective, the URL http://yousite.com/displayCategory.aspx?CategoryID=5 is a mess. Usability expert Jakob Neilsen recommends that URLs be chosen so that they:

  • Are short.
  • Are easy to type.
  • Visualize the site structure.
  • "Hackable," allowing the user to navigate through the site by hacking off parts of the URL.

I would add to that list that URLs should also be easy to remember. The URL http://yousite.com/displayCategory.aspx?CategoryID=5 meets none of Neilsen's criteria, nor is it easy to remember. Asking users to type in querystring values makes a URL hard to type and makes the URL "hackable" only by experienced Web developers who have an understanding of the purpose of querystring parameters and their name/value pair structure.

A better approach is to allow for a sensible, memorable URL, such as http://yoursite.com/products/Widgets. By just looking at the URL you can infer what will be displayed—information about Widgets. The URL is easy to remember and share, too. I can tell my colleague, "Check out yoursite.com/products/Widgets," and she'll likely be able to bring up the page without needing to ask me again what the URL was. (Try doing that with, say, an Amazon.com page!) The URL also appears, and should behave, "hackable." That is, if the user hacks of the end of the URL, and types in http://yoursite.com/products, they should see a listing of all products, or at least a listing of all categories of products they can view.

How to configure URL rewriting in asp.net 2.0?
Add the following code in web.config with proper mapping informations.

<?xml version="1.0" ?">
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web">
<urlmappings enabled="true"">
<add url="~/Autos.aspx" mappedurl="~/Default.aspx?category=autos">
<add url="~/Games.aspx" mappedurl="~/Default.aspx?category=games">
</urlmappings>
</system.web>
</configuration>

Now, add the mapping in the ISAPI filter of IIS.
Say, if you use the extention ".mspx", add the extension to the ISS pointing to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll. That means, whatever request with extension .mspx should be handled by aspnet worker thread.

HTH

Sunday, June 03, 2007

"The server instance specified was not found" error message when you perform an operation on a virtual server in Windows SharePoint Services

In Microsoft Windows SharePoint Services, when you use the Stsadm.exe command-line tool to perform an operation on a virtual server by using its host name, or try access a site by URL using SharePoint Object Library, or when you create a custom Web application that uses the Windows SharePoint Services object model to perform an operation on a virtual server by using its host name, you may receive the following error message:

The server instance specified was not found. Please specify the server's address and port.

eg:-

SPSite MySite = new SPSite(http://spsite);
String SiteURL = MySite.Url.ToString ();

Cause
This may occur due to the fact that virtual server of the site is assigned a specific IP address (instead of "All Unassgined" configuration) and server name is mapped in Domain Control (DNS). In these cases, WSS will not query DNS to resolve the host name since the hostname is not mapped in the metabase.

Resolution

Assign a host header name to the IP address that is configured for the virtual server in IIS. By doing so, Windows SharePoint Services can map the virtual server to the host name. To assign a host header name for a virtual server in IIS, follow these steps:
  1. Start Internet Information Services (IIS) Manager.
  2. Expand ServerName, and then expand Web Sites.
  3. Right-click the Web site that you want, and then click Properties.
  4. Click the Web Site tab, and then under Web site identification, click Advanced.
  5. Under Multiple identities for this Web site, click Add.
  6. In the Add/Edit Web Site Identification dialog box, specify an IP address, TCP port, and host header value, and then click OK
  7. Click OK, and then click OK.
  • If the IP address of the virtual server in IIS is set to All Unassigned, perform the operation on the virtual server by using the server name.
  • Perform the operation on the virtual server by using the IP address that is assigned to the virtual server.
-::-

Friday, June 01, 2007

Error on security tab : Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion' in ASP.Net 2.0 Web Administration Tool

Error while configuring ASP.Net 2.0 membership provider with Web Administration tool

You may receive the following error while configuring the .net 2.0 membership provider.

Error on security tab : Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion' in ASP.Net 2.0 Web Administration Tool

Resolution

You must have to create the SQL schema in the database you're going to use for membership. To do this, you can run aspnet_regsql from the v2.0 directory. That'll open up a wizard and walk you through the steps to create the SQL stored procs and such that are needed for the security and membership stuff

-::-