Sunday, August 12, 2007

How to pass array from ASP.Net to Javascript?

There are scenarios where we have to pass list of values as arrray from ASP.Net to client side (Javascript). And we don't have a clear cut method to accomplish this.

To acheive this do as follows:-

  • Prepare the string of values seperated by commas, say string ArrayString = 'Hythem', 'Apple','Banana'
  • Create the array while passing the values to the javascript

See the code below:-

string ArrayString = 'Hythem', 'Apple','Banana';
ntxtAmt.Attributes.Add("onkeyup", "javascript:testme(new Array(" + ArrayString + ");");


Saturday, July 21, 2007

How to retrieve the blob object in WinForms to physical location with "Binary Streaming" enabled ?

See the snippet below, how it works!!

SqlConnection Conn = new SqlConnection("<>");
SqlCommand Cmd = new SqlCommand("select docobject, filetype,docname from documents where docid = 23", Conn);
Cmd.CommandType = CommandType.Text;
SqlDataReader Reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
string DocumentName = null;
FileStream FStream = null;
BinaryWriter BWriter = null;
byte[] Binary = null;
const int ChunkSize = 100;
int SizeToWrite = 0;
MemoryStream MStream = null;
while (Reader.Read())
DocumentName = Reader["docname"].ToString();
// Create a file to hold the output.
FStream = new FileStream(@"c:\" + DocumentName, FileMode.OpenOrCreate, FileAccess.Write);
BWriter = new BinaryWriter(FStream);
Binary = (Reader["docobject"]) as byte[];
SizeToWrite = ChunkSize;
MStream = new MemoryStream(Binary);
for (int i = 0; i < Binary.GetUpperBound(0) - 1; i = i + ChunkSize)
if (i + ChunkSize >= Binary.Length) SizeToWrite = Binary.Length - i;
byte[] Chunk = new byte[SizeToWrite];
MStream.Read(Chunk, 0, SizeToWrite);

Tuesday, July 10, 2007

Add image to ASP.Net 2.0 Menu navigation control

To give more beautiful for intranet systems / sites, we may need icons/images to be displayed along with the menu caption.

To map image with a site map node, add a custom property, say, "menuImage" in the sitemapnode tag as below

<siteMapNode url="~/pages/wemployee.aspx" title=":: Employees" description="" menuImage="~/Images/viewdetail.gif" />

Now, in the code behind, add the code below:-

protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
e.Item.ImageUrl = ((SiteMapNode)e.Item.DataItem)["menuImage"];

Infact, you can have a harcoded image path as well.


Tuesday, July 03, 2007

"Error in File < Path..>\ASPNET\LOCALS~1\Temp\Employees {BBE0A87A-CFF9-4682-A6AD-B0E256CF4793}.rpt:" Crystal Report error in ASP.Net 2.0

Did you ever encounter with this error saying
"Error in File C:\DOCUME~1\..\ASPNET\LOCALS~1\Temp\Employees {BBE0A87A-CFF9-4682-A6AD-B0E256CF4793}.rpt: Get page number for group failed" while working with Crystal Report in ASP.Net 2.0

This error will occur when you try a postback in the .net page by a tree node click or so. And the reason behind is while postback, report is not able to find the data.

To avoid this error, enable the caching by making the prOperty of CrystalReportSource "Enable Caching = true".


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; }
.noprint{display:block !important;}


@media print {
body {fcolor:Blue;}

and the page is

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

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:
There are two downsides to creating a website with such URLs. First, from the end user's perspective, the URL 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 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 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," 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 page!) The URL also appears, and should behave, "hackable." That is, if the user hacks of the end of the URL, and types in, 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 2.0?
Add the following code in web.config with proper mapping informations.

<?xml version="1.0" ?">
<configuration xmlns="">
<urlmappings enabled="true"">
<add url="~/Autos.aspx" mappedurl="~/Default.aspx?category=autos">
<add url="~/Games.aspx" mappedurl="~/Default.aspx?category=games">

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.


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.


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

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.


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


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


Thursday, May 31, 2007

How to handle hidden columns/values in gridview 2.0?


It is always a "Fact" that we are not supposed to disclose any confidential data to the browser, whether it is a primary key or not. At the same time we may need those values for further processing of the page logic. In datagrid (.net 1.1), we always used to get the hidden values in the viewstate and we can make use of those values in client side script.


However, the situation is changed now!. Due to security breach, microsoft has come up with new term "DataKeys" in order to hide the hidden fields forever (from rendering). You cannot see the hidden column values in View State. At the sametime, you can have multiple datakeys for a particular gridview control. Doing so, you can extract the values of those fields against each row, but only from code behind as it is not rendered in the browser.

You can access the values as below :

where 'i' represent the rownumber and 'j' represent the index of DataKeys (defined).


Wednesday, March 14, 2007

Is cross database referential integrity possible ?

Cross database referential integrity is not possible in SQL. Hence deletion of any master data stored in one database will make orphan the related data in other databases (transaction db). Also, if cross – database constrain is possible, then it is more or less similar to saying that you can have PK-FK relation for databases. i.e., you cannot drop a database when there are some PK records for some FK records in the other database. Right? Any thought? Let me know if you find any thing!!

And as per the third party tool, remote-keys this could be achieved. But it is more like a work around, achieving the same programmatically (DDL statements in triggers)

Hence to my knowledge, it is not possible in SQL where as the feature is available in SYBASE. Any different thought ?

What developer says?

What Third Party says?


Wednesday, February 21, 2007

IE Web User Controls deployment in SharePoint 2003 - How to?

Although Microsoft has stopped support for MS IE Web Controls, we would use it when we need some conrols like TreeView in .Net 1.1 - say sharepoint 2003

1. Add the controls in .ascx (used for web parts)
2. While deploying, copy the Microsoft.Web.UI.WebControls.dll to the bin of WSS root
3. Deploy the above dll in GAC (if required)
4. Run the Build.Bat file from C:\Program Files\IE Web Controls (installation folder). While doing this, care should be taken for CSC.exe location - either run it from VS.Net Command prompt (after switiching to the above location) or include the path of CSC.exe in the "Environment Variables" of system. This will generate a \build\Runtime folder with script file required for the controls
5. Copy the above folder to the root of WSS
6. Exclude the path for the above folder, say webctrl_client (only type the folder name as it is in the root folder) by configuring the virutal server (use SharePoint Central Administration page)

Now it will work!!


Tuesday, February 20, 2007

How do we generate XSD in VS.Net for reporting from a stored procedure containing #temp tables (local) ?

In many scenarios we may have to use local temp tables in procedures instead of functions returning tables. Always, temp tables are best in performance. When there is any temp table involved in an sp, say for reporting, VS.Net will not allow you to generate a typed dataset (.xsd) out of that.


1. Comment the lines containting temp tables in sp
2. Generate .xsd file in .net IDE
3. Uncomment the comments

Yeah!!! It worked


Monday, February 12, 2007

How to consume a Share Point web service in ASP.Net web ?

It is always an appreciable effort if we consume an existing system as primary reference instead of storing same data here and there

Follow the steps below:

1. Add web reference in the IDE with URL of SPS site
2. Create a proxy class with WSDL.exe utility (available in the VS.Net Tools menu)
Go to command prompt and type as below
wsdl /out: c:\ProxyClass.cs http://server:90/_vti_bin/lists.asmx
Find more options of wsdl here
3. Consume the webservice via proxy class (shouled be added to the project)
4. Now you should get all the published methods in web service via proxy class


Sunday, February 11, 2007

Crystal Report prompts for report parameters in VS.Net 2005 after being upgraded (VS.Net 2003)

I got parameter prompts when i run my windows application after upgrading to framework 2.0. The application was built on .net 1.1 and was running successfully


Pass the parameter after binding the report document to the report viewer component as below. (I passed it before binding to CRV component in .net 2003)

crv.ReportSource = rptDoc;
rptDoc.SetParameterValue("BRAND", Application.ProductName);


Saturday, February 10, 2007

Configuration Error - Unrecognized attribute 'xmlns' web.config - 2.0

When you try running a 2.0 web application, you may receive a web.config error as "Unrecognized attribute 'xmlns'"

Line 1: <?xml version="1.0"?>
Line 2:
Line 3: <configuration xmlns="">
Line 4:

Your system/server must be running more than one version of .net framework

1. Choose Start -> Control Panel -> Administrative Tools -> Internet Information Services
2. Expand the nodes until you can see your virtual directory
3. Right-click on the virtual directory and click Properties
4. Select the ASP.NET tab
5. Under the ASP.NET version, choose 2.0.50215.0
6. Click OK.

Wednesday, February 07, 2007

VS.Net 2005 Templates not found after applying the patch VS80-KB915364-X86-ENU

You might have surprised seeing no templates when you open the VS2005 IDE after installing the patch VS80-KB915364-X86-ENU


Regenerate the templates by running 'devenv /installvstemplates' or reinstall
Visual Studio.
Note: Action requires Administrator privileges.


SQL Server 2000 installation fails with "...previous program installation..." error message

When you install SQL Server 2000, this error message may occur:

"A previous program installation created pending file operations on the installation machine. You must restart the computer before running setup."

1.Run the Windows Registry Editor
3.Delete the pendingfilerenameoperations key

Now it should work!!


Tuesday, February 06, 2007

File upload size limitation in <asp:FileUpload> control

You may receive surprise results when you try to upload a file of size more thatn 4mb with <asp:FileUpload> control

You may not realize it, but there is a limit to the size of a file that can be uploaded using this technique. By default, the maximum size of a file to be uploaded to the server using the FileUpload control is around 4MB. You cannot upload anything that is larger than this limit.

To change this size limit, you make some changes in either the web.config (found in the ASP.NET 2.0 configuration folder at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG) or your application's web.config file.

In the web.config file, find or add a node as following inside System.Web tag:

apartmentThreading="false" />

By default, this is set to 4096 kilobytes (KB). Simply change this value to increase the size of the files that you can upload to the server. If you want to allow 10 megabyte (MB) files to be uploaded to the server, set the maxRequestLength value to 11264, meaning that the application allows files that are up to 11000 KB to be uploaded to the server.


Monday, February 05, 2007

How to embed WMP in pages and how can we redirect the request when the movie ends

You can either user <img> or <object> to embed movies in *.aspx. But to capture the events, you should use the later

Use the below <object tag> to embed WMP in .aspx / html pages
<object id="VIDEO" width="100%" height="100%"
<param name="URL" value="http://localhost/QaQcTraining/movies/start.wmv" />
<param name="SendPlayStateChangeEvents" value="True" />
<param name="AutoStart" value="True" />
<param name="uiMode" value="none" />
<param name="windowlessVideo" value="True" />
<param name="stretchToFit" value="true" />

Now, use the below script to capature the events of WMP
<script language=jscript FOR = VIDEO EVENT = playStateChange(NewState) type=text/jscript>
// Test for the player current state, display a message for each.
switch (NewState){
case 1:
//myText.value = "Stopped";
//redirecting to different page after the movie plays

case 2:
//myText.value = "Paused";

case 3:
//myText.value = "Playing";

// Other cases go here.

//myText.value = "";

Sunday, January 28, 2007

SQL2000 Enterprise Manager not working after installing SQL2005 version in the same box

When you install both versions together, one after another and try opeining the Enterprise Manager, you may recieve a message as below

snap-in failed to initialize
CLSID: {00100100-1816-11d0-8eF5-00AA0062c58F}

Try reregistering sqlmmc.dll
ie.regsvr32 C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqlmmc.dll


Wednesday, January 24, 2007

How to implement AJAX in Share Point 2003 ?

There is no straightaway thing to accomplish this. Although Microsoft has released its AJAX toolkit, it is only compatible with .net framework 2.0 while SP2003 is built on .net framework 1.1. To get around this, we have to go for some javascript libraries. is the best best to achieve. This is basically an open source with rich control functionality built on the top of microsoft's standard web controls. It supports both versions of .net frameworks as well.
To get the ajax functionality for a set of controls in a web page, add anthem panel and embed all standard web controls within it.


To get the functionality for a set of controls in the web page, use Anthem Panel control and embed the controls within it. Or else use individual Anthem Controls.

<anthem:panel id="MenuPanel" runat="server" AddCallBacks="true" AutoUpdateAfterCallBack="true"
TextDuringCallBack="Please wait..." width="100%">

In the above configuration, "Please wait..." would be displayed in the control's Text portion while callback happens (TextDuringCallBack). For example, on button click, button text will change to "Please wait.." and remain till callback finishes. AutoUpdateAfterCallBack ensures that controls are refreshed after callback.
While porting the anthem technology to SP server, there are times when the callback updates doesn't happen properly. In that case, in the button click events (triggering events), add MenuPanel.UpdateAfterCallBack=true;

Now develop the webpart and call the webpages as .ascx.

It works great! Enjoy!