Tuesday, November 2, 2010

HTML Encode and Decode

The link below will help you all for encoding and decoding HTML text

http://centricle.com/tools/html-entities/

Try it ;)

Enable HTTP-GET and HTTP-POST protocols

To enable Http-Get and Http-Post protocols for a web application or webservice application
you have to add to system.web the following lines:

<webServices>
<protocols>
<add name="HttpPost" />
<add name="HttpGet" />
</protocols>
</webServices>


for more details about ASP.net configuration Click Here
Hope it helps

Wednesday, October 27, 2010

(ASP.NET) Prevent pages from being displayed if user clicks back button on his browser

When using asp.net applications, you might face a problem of clicking the back button of his browser (internet explorer) after he logged out.
It is expected that the user could not be able to do that ,buy you might face that he can do it.
The problem could easily be solved by using the code below:
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

The code above sets the expiration date of the page to a date that has been based and informing the browser not to cache or store this page .
Hope it helps all of you ...

Tuesday, August 31, 2010

Silverlight Error Messages : Could not download the Silverlight Application

When deploying a Silverlight application on IIS you may get a script error: 'Could
not download the Silverlight application'. The cause of this problem is that IIS cannot understand the xap object and it is considered an unknown extesion.

IIS won’t let you access those files on the server. When you installing the Silverlight SDK on your development computer the mime type is installed on your IIS, yet servers without that SDK or the latest version and service packs won’t know about xap.

The solution for this problem is pretty easy.
All what you need to do is to add the MIME type to website properties for .XAP File type(it is application/x-silverlight-app).

So, in MIME Add new :
File name extension : .xap
MIME type : application/x-silverlight-app

Hope it helps all of you,

Happy coding

Tuesday, August 10, 2010

Class MetadataType and property DisplayName

Target : No specific target but I used it when I was working in MVC Project.

Today's issue is not a big deal and did not take any time to resolve ,but I think that it will help too much.
In view I was using html.labelfor and I was binding to GuestResponse model class.

The problem was that the displayed text for the label is the property name and I want another friendly name.

The picture below will display a good details of using a MetadataType attribute of GuestResponse class. This attribute specifies the metadata class to associate with a data model class 'GuestResponse_Metadata' in this class I added a DisplayName attribute.

Why do not I use the DisplayName attribute directly?

My project was complicated more that the sample I am talking about. Data layer was generated by a generation tool and any change will be overriden when regenerating for any reason.

I hope it helps.

Monday, August 9, 2010

.Nettiers problem when changing column type

When using .nettiers I have found a problem of generation when changing column type.
The only way to resolve this problem on my point of view was to select another name for that column.
This change will be a huge problem as sometimes this column is used in stored procedures, functions or buisness layer.
One day I decided to spend a time looking for a solution for this problem.
I tried to change column name and rebuild then change it back, generate and rebuild, but the problem was still existing !!
How it knows the old name ?!!
From the above question I was sure that there is a place that caches it and finally I got it.
Using code smith generation tool that is used for generation there is a mapping file.
When I changing the mapping to a new file map ,then regenerate. The problem solved !!
This mapping file is a config XML file that has all tables definitions and that was the problem :)
Actually I am very happy for resolving this problem and saving a lot of time of chaning column name.

Hope it helps all of you and happy coding ;)

Thursday, August 5, 2010

Reporting Services 2008 and IIS

One of the requirements for SQL Server Reporting Services (SSRS) in the 2000 and 2005 releases was that Microsoft's Internet Information Services (IIS) should be installed on the system as the Web Services product for running the Report Manager and Report Server applications.

I was assuming that will be the case on SQL Server Reporting Services 2008 ,but I figured out that nothing installed on the IIS !!

I thought that someting was wrong ,but after a while I start googling to find out the reason because everything was working well and nothing on IIS !!

YES..
It was a surprise for that when I found that SQL Server Reporting Services 2008 are not more dependent on IIS.

SQL Server 2008 no longer depends on IIS (Andrew Fryer) to make it easier to configure and to reduce the attack surface of the report server.

Config simplification is one of the reasons for the move to not use IIS, but the other is around memory, thread and scale management, if you have every tried to generate a 100 page PDF report you will know what I mean (Evan Garden).

Now in SQL Server Reporting Services 2008, we do not need IIS at all. The Report Manager and Report Server applications can be supported using the HTTP listener (http.sys) that is already part of Windows 2003 Server and above. This is a much more secure architecture. I tested this out on my upgraded test server. I was able to stop my existing IIS service and still run my existing reports successfully(Reporting Services 2008 is IIS Agnostic By Brian Egler).

Tuesday, April 20, 2010

Introducing Windows Azure Platform

Using computers in the cloud can make lots of sense. Rather than buying and maintaining your own machines, why not exploit the acres of Internet-accessible servers on offer today? For some applications, both code and data might live in the cloud, where somebody else manages and maintains the systems they use. Alternatively, applications that run inside an organization—on-premises applications—might store data in the cloud or rely on other cloud infrastructure services. However it’s done, exploiting the cloud’s capabilities can improve our world.
But whether an application runs in the cloud, uses services provided by the cloud, or both, some kind of application platform is required. Viewed broadly, an application platform can be thought of as anything that provides developer-accessible services for creating applications. In the local, on-premises Windows world, for example, this includes technologies such as Windows Server, the .NET Framework, SQL Server, and more. To let applications exploit the cloud, cloud application platforms must also exist.
Microsoft’s Windows Azure platform is a group of cloud technologies, each providing a specific set of services to application developers. As Figure shows, the Windows Azure platform can be used both by applications running in the cloud and by on-premises applications.




The components of the Windows Azure platform are:
Windows Azure:
Provides a Windows-based environment for running applications and storing data on servers in Microsoft data centers.
SQL Azure: Provides data services in the cloud based on SQL Server.
Windows Azure platform AppFabric: Provides cloud services for connecting applications running in the cloud or on premises.

Monday, April 19, 2010

Mastering the iteration of an agile development

The heartbeat of Agile development is the iteration – the ability of the team to create working, tested, value delivered code in a short time box.

Iteration: The heartbeat of agility

The base construct of agile and iterative development is the iteration—the ability of the team to create working, tested, value-delivered code in a short time box—with the goal producing an increment of potentially shippable code at the end of each iteration. This is a significant challenge for the team, and mastering the process takes some time to accomplish. In this article I will try to be brief and just hit the important points I want to share.

The standard Iteration Period

Most people agree that iterations are a fixed, constant length and typically should not vary in length over the course of a release or a project. But the length of the iteration is an agile variable. From the literature, experts recommend a length of 1 to 4 weeks. But a week may be too short and a month is too long, so finally they typically arrive at is to standardize on iterations of 2 weeks in length.

There are many advantages to this approach:

  • There is some overhead in planning and closing iteration; in a 2-week iteration, the overhead is well proportioned to the amount of work that can be accomplished in the period.
  • Two weeks is sufficient time to get some amount of meaningful development done.
  • This cycle provides more opportunities to succeed or fail early.
  • The 2-week rhythm is a natural calendar cycle that is easy for all participants to remember.
  • Scheduling is trivial: "If it's the second Wednesday, I need to be preparing my demo for Friday.""Demo day" occurs every other week, at exactly the same time and place, allowing key stakeholders to attend.
  • Velocity can be measured and scope can be adjusted more quickly.

Planning and executing the iteration

No matter the length, all iterations have the same pattern, and that is part of the discipline and manufacturing-like routine of agile development. An iteration consists of three phases, as Figure illustrates.

  • The first phase is a short planning session (less than a day) during which the iteration backlog is reviewed and prioritized, estimates are established, and the team commits to the work in the iteration.
  • The second is the development phase, when the backlog items are implemented in code and tests.
  • The final phase involves delivery of the new system increment built during the iteration and assessment of the iteration.

Iteration Planning

At the beginning of each iteration, the team holds an iteration planning session during which it reviews the prioritized items in the backlog, selects and reviews the stories for the current iteration, and defines and estimates the tasks necessary to deliver the increment of work. There is a high degree of granularity involved because tasks are typically estimated in "ideal developer days" or even hours. In keeping with the agile practice of just-in-time design, it is during this session that the details of the requirements are discussed and negotiated.

The primary concern of iteration planning is to define and accept a reasonable scope for the iteration. Iteration planning begins with revising and refining the list of prioritized work in the backlog. Product owners and the development team may add or reduce features, defects, and other infrastructure work on the basis of the current business situation. Business priority, risk, and rough estimates are assigned to new items or may be revised for existing items. The product owners then re-rank the work items and select a scope of work to propose for the iteration.


The development team is given an opportunity to discuss the proposed work with product owners until each item is well enough understood for the development team to prepare a list of engineering tasks and provide detailed estimates. The development team then estimates the engineering tasks for each proposed backlog item. The development team then presents its estimates to the product owners.

By adding up the development team's estimates, the team can calculate the apparent scope of the iteration and have an indication of whether the scope can be achieved. However, the final scope of the iteration is the result of a negotiation between product owners and the development team. During this negotiation, product owners may adjust certain backlog items in ways that make them less costly to develop, trade out entire backlog items for others, or ask for adjustments to certain estimates provided by development.
The team should keep the following guidelines in mind during the iteration planning meeting:

• Have the iteration planning meeting on the first day of the iteration, first thing in the morning. The meeting should last no more than 4 hours.

• Create task estimates for each story on the basis of ideal effort hours, or points.

• When estimating, if a story breaks out into seven or more tasks, consider splitting the story.

• Be sure that there is at least one story with a demonstrable function included in the iteration.

• Remember that the product manager owns the story priorities, and the development team owns the tasks and the estimates for those stories.

• When first implementing agile practices, consider setting a "code freeze" a few days prior to the end of the iteration, because the team is likely still practicing waterfall within the iteration.

• Remember that the team's velocity (available resources factored by existing velocity) changes from iteration to iteration.

• Once the iteration is underway, no change requests by the product manager are allowed. Any new or changed stories should go into the backlog.

Iteration Cycle


Iteration cycle is repeated until all backlog items are completed. The following figure illustrates the iteration cycle:

Take Responsibility

Having committed to the iteration plan, the team is faced with the question of how to allocate that work to the members of the development team. The two basic approaches to allocating work are that the Agile/Scrum. Master can assign work to developers or the developers can choose the work they will do.


The process of developers taking responsibility for work must be supported by a visible indicator showing who is responsible for what work and by daily status meetings during which status and issues can be discussed.


Develop


Once a developer takes responsibility for a backlog item, he or she then:

• Elaborates requirements (if not already elaborated).

• Designs.


• Writes the test (first in some practices) and writes the code.


• Executes the test suite on the build.

• Integrates program code and tests into a build of the system.


Deliver Story

The developer delivers the new functionality or defect fix by checking the code into the source control system and including it in a build of the system. The unit test suite and other appropriate tests are run before the code is checked in to ensure that the changes do not break the build.

Declare Story Completion

Once the developer has integrated his or her work into a build of the system, the backlog item is declared complete, signaling other members of the development organization that the backlog item is ready. For example, the testing group now knows it can include the new functionality or defect fix in its testing efforts and can start automated tests of various kinds (functional, acceptance, performance, etc.).

Accepting the Iteration

The final activity in an iteration is to reflect on and assess the results. The goal of assessment is to mine the lessons learned during the iteration and then adapt the development process accordingly. The assessment allows the team to continually improve the throughput of the development process and the quality of the resulting system.

The other major activity that occurs during assessment is a "closing" process whereby unfinished items are put back into the release backlog as work to be done. The iteration is concluded, and the closed iteration backlog becomes a record of the work completed during the iteration.

Tracking Iteration

Since there are relatively few stories in an iteration, tracking the status of each is a fairly simple matter, and it provides an objective look at progress. Status can be tracked by hanging visual indicators of state information (defined, complete, accepted) on the wall, moving cards from one area of a wall to another, or for larger and distributed teams, using automated tools.

Since iterations are fixed in duration, another primary way the team and its managers can gauge progress in the aggregate is to continuously monitor current status and also estimate how much work remains. Computing the estimated remaining work in the iteration at a given point in time requires two pieces of information: the total of the estimates for all backlog items that are not yet started and the estimated remaining effort for any in-progress backlog item. The sum of those two amounts represents the estimated remaining work to be completed during the iteration. Plotting this value each day of the iteration produces what is called a burndown chart, as the example in Figure illustrates.

References

  • Mastering the Iteration: An Agile White Paper, Rally Software Development Corporation.
  • ScalingSoftware Agility: Best Practices for Large Enterprises, Addison-Wesley, 2007

Thursday, April 15, 2010

Silverlight Cross-Domain Web Services Calls

Target : Silverlight 3.0
Silverlight allows you to make web service calls to web services that are a part of the same website with no restrictions. Additionally, Silverlight allows you to call web services on other web services if they explicitly allow it with a policy file. To make this possible, you must create a file named clientaccesspolicy.xml and place it in the root of your website (for example, in the c:\inetpub\wwwroot directory of an IIS web server).
The clientaccesspolicy.xml file indicates what domains are allowed to access your web service.

You will notice in that file that here I have configured the service to allow connection from a specific URI. You might insert an asteric '*' to allow unlimited access which is not a perfect solution.

You can restrict the resources to share. You can prevent subpaths and so on.

But where to put this xml file ?

This is an important question which I was googling for a long time. Although I wrote that you can put it in the IIS root directory, you will find that this is not the situation when you debug the solution and your project is not added yet to IIS or a specific server. In my condition I was having a silverlight project 'FileServiceApp' , an ASP.net web site that uses the xap file of 'FileServiceApp' and a service project 'WcfFileService' that has the WCF services that I want to use. This file should be used in the 'WcfFileService' Project.

If your services are inside a web project so the xml file should be placed on the root path and not in the assemblies path.

I tried and It works perfectly.




Monday, April 12, 2010

Resolving MVC Paths Problem

Target: ASP.NET MVC
If you are using MVC approach while using ASP.NET you might notice the problem of relative paths specially if you use
JQuery with it.

This issue can be solved using Url.Content method which converts relative path to absolute path
I hope it helps


<%= Url.Content("~/content/...") ... %>

Configure SQL Server 2005 to allow remote connections

Configure SQL Server 2005 to allow remote connections


 

To configure SQL Server 2005 to allow remote connection you have to do the following steps:

Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer Edition

  1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
  2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
  3. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.

    Note Click OK when you receive the following message:

    Changes to Connection Settings will not take effect until you restart the Database Engine service.

  4. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.

Enable the SQL Server Browser service

  1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
  2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
  3. On the Surface Area Configuration for Services and Connections page, click SQL Server Browser, click Automatic for Startup type, and then click Apply.

    Note When you click the Automatic option, the SQL Server Browser service starts automatically every time that you start Microsoft Windows.
  4. Click Start, and then click OK

Create exceptions in Windows Firewall

These steps apply to the version of Windows Firewall that is included in Windows XP Service Pack 2 (SP2) and in Windows Server 2003. If you are using a different firewall system, see your firewall documentation for more information.

If you are running a firewall on the computer that is running SQL Server 2005, external connections to SQL Server 2005 will be blocked unless SQL Server 2005 and the SQL Server Browser service can communicate through the firewall. You must create an exception for each instance of SQL Server 2005 that you want to accept remote connections and an exception for the SQL Server Browser service.

SQL Server 2005 uses an instance ID as part of the path when you install its program files. To create an exception for each instance of SQL Server, you must identify the correct instance ID. To obtain an instance ID, follow these steps:

  1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager.
  2. In SQL Server Configuration Manager, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click Properties.
  3. On the SQL Server Browser Properties page, click the Advanced tab, locate the instance ID in the property list, and then click OK.

To open Windows Firewall, click Start, click Run, type firewall.cpl, and then click OK.

Create an exception for SQL Server 2005 in Windows Firewall

To create an exception for SQL Server 2005 in Windows Firewall, follow these steps:

  1. In Windows Firewall, click the Exceptions tab, and then click Add Program.
  2. In the Add a Program window, click Browse.
  3. Click the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe executable program, click Open, and then click OK.

    Note The path may be different depending on where SQL Server 2005 is installed. MSSQL.1 is a placeholder for the instance ID that you obtained in step 3 of the previous procedure.
  4. Repeat steps 1 through 3 for each instance of SQL Server 2005 that needs an exception.

Create an exception for the SQL Server Browser service in Windows Firewall

To create an exception for the SQL Server Browser service in Windows Firewall, follow these steps:

  1. In Windows Firewall, click the Exceptions tab, and then click Add Program.
  2. In the Add a Program window, click Browse.

Click the C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe executable program, click Open, and then click OK.

Note The path may be different depending on where SQL Server 2005 is installed.

Monday, March 29, 2010

Resolving IE z-index problem of all controls

The following code resolves all z-index problem :
/*Fixing menu z-index problem and all z-indexing problem of IE */
$(function() {
var zIndexNumber = 1000;
$('div').each(function() {
$(this).css('zIndex', zIndexNumber);
zIndexNumber -= 10;
});
});


Happy coding ...

Thursday, March 25, 2010

Unregister an assembly using regasm.exe command

You might know that to register an assembly you can use 'regasm' command.

But what if you want to unregister this assembly ??
To unregister an assembly using regasm.exe command that had been registered before. You could you can add a /unregister to regasm syntax :
'regasm /unregister [assembly full path]'

Wednesday, March 24, 2010

Using Command Prompt for running SQL commands

Usually on the costumer's computer, if you installed an instance of Microsoft SQL Server Express, you will not install the management studio to prevent the user from using it badly and harm your valued database. But in this case you might need to run a SQL command.

You can use the command prompt to do the job.

From command prompt you can run a 'sqlcmd'.

The simplified syntax for that is 'sqlcmd -S servername'. ex. 'sqlcmd -S adel-pc\SQLEXPRESS' and now you are on the sever and you can run any Select, Update, delete , backup, restore .. etc comands or any sql command you want by accessing database for example 'USE master GO' and so on ...

You can find here a full description of sqlcmd.

Have fun.

Tuesday, March 23, 2010

Ajax Control Toolkit : ScriptManager and .net framework 3.5 'AjaxControlToolkit' is undefined (javascript)

Problem
When moving an ASP.NET application that uses AJAX and has an update panel from .net framework 2.0 to .net framework 3.5 you might have a problem that 'AjaxControlToolkit' is undefined although you have included it and it works on the developer PC.

Actually this problem makes me hit my head on a wall as I did not see any reason for that error.

I looked for an Ajax Extensions msi setup for .net framework 3.5 but thanks to Microsoft it is included in .net framework 3.5 setup. So what is the problem.

Solution
In such situation googling will not provide you with a satisfactory answer for that. But I hope that after this post, I might save you tons of hours looking for a solution.

In Script Manager I have added a CombineScripts="false" property and it do the trick :)

So what is it means. Read the following paragraph that will illustrate in details:
The ToolkitScriptManager class derives from ScriptManager and enables the automatic combining of multiple script files in the corresponding web page. Any scripts (and localized script resources) coming from assemblies indicating their willingness to have their scripts combined (with the new assembly-level ScriptCombine attribute) will automatically be combined into one file for download by the user's browser. This combining action (and the automatic compression of the resulting file) can dramatically reduce the number of round-trips made by the browser to fetch scripts and correspondingly improve the page's responsiveness. The combined script file will be cached by the user's browser just like its individual parts would have been with the ASP.NET AJAX ScriptManager's default ScriptResource.axd behavior. Any changes to the page or the associated DLLs invalidates the cached copy of the combined scripts and prompts a re-download during the next page access.

This new behavior is enabled by default for ToolkitScriptManager and can be disabled by setting its CombineScripts property to "false". Assemblies containing scripts which should not be combined in this fashion for some reason may use the ScriptCombine attribute's ExcludeScripts/IncludeScripts properties to specify exactly which scripts can be combined. The absence of the ScriptCombine attribute on an assembly means that none of its scripts can be combined in this manner; this is an explicit opt-in model for Assemblies.

Thursday, March 18, 2010

WIX Deployment

The following is a setup setups using WIX including additional important info. That you might find in a hard way.


  1. Install WIX (15 MB)

    http://sourceforge.net/projects/wix/files/


  2. Build your application as release.
  3. Run heat.exe command given full paths for any input file or directory. This will generate application.wxs file that contains GUIDS of release components.
  4. Use the following command to remove unwanted files from the released application files:

    xcopy RELEASE_PATH EXECLUDED_PATH /EXCLUDE:exclude.txt /E /Y

    where execlude.txt is a text files that contains unwanted files' extentions. Its content might be as follows:

    \.svn

    \Properties

    \obj

    \Helper

    .pdb

  5. Refer to WIX website to build your WIX deployment application.
  6. Install BootStrapper Manifest Generator that matches your Visual Studio version from here.
  7. This will help you to create prerequisites for your application.
  8. Finally you can use a .pat file to gather all in a single file. This .pat file may contains a code like this:

    C:\Program Files\WinRAR\WinRAR" a -r -ep1 SETUPNAME SETUP_OUTPUT_PATH\* -s -sfx -zAnswers.diz -iiconico107.ico -m0


    You have to note that WinRAR application should be installed, and Answers.diz is a .diz file that may contains a code like :

    Overwrite=1

    TempMode

    Title=SETUP_TITLE

    Silent=2

    Setup=setup.exe


    And ico107.ico is an ico file that will be the icon of the generated setup file. So that your setup including the prerequisites can be in a single setup file.


WIX - Add an assembly component to GAC

Reader background
- Windows Installer XML setup (WIX)
- Global Assembly Cache (GAC)
- My previous post on WIX

Problem
You need to install an assembly to GAC.

Solution
After genertion of wxs file of the assembly component using heat.exe command, you need to add it to GAC.

After googling and looking for a solution, finally I found it and it was very simple and makes the job as I want.
The solution was to add two properties tothe file of the component:
  1. AssemblyManifest. (set it to the file Id)
  2. Assembly. (set it to .net)
Try it and I hope that it helps you.

Thanks

Tuesday, March 16, 2010

My WIX setup important notes

Windows Installer Xml (WIX)

The Windows Installer XML (WiX) is a toolset that builds Windows installation packages from XML source code. The toolset supports a command line environment that developers may integrate into their build processes to build MSI and MSM setup packages.
When using WIX you might -sure actually- face many problems. I tries here to save you a time with a common tools that might help you.
I started using it since 2009 and now I am on 2010 and I need it again.
I tried to find tools I was using before and here I will add it one by one to easily find it and share it with all of you.

Let's Start

- Heat.exe
Heat is used to generate WiX authoring from various input formats.Every time heat is run it regenerates the output file and any changes are lost.
You have to note here that you should enter full paths or you will get an endless errors that you will never know its reason !!

- Setup Log
If your MSI doesn't work properly, how do you troubleshoot? The easiest way is to turn on tracing to get the setup log file. The command line is:
msiexec /i product.msi /L*v log.txt

- Cabarc
Generates a .cab file if you want to install a component from your web application. This component might be a .net activeX control.
Click here to install it.

-Microsoft Visual Studio 2008 Web Deployment Project
If you want to use WIX for a web project. You might need 'Microsoft Visual Studio 2008 Web Deployment Project' which is a Visual Studio 2008 Web Deployment Projects provide additional functionality to build and deploy Web sites and Web applications in Visual Studio 2008. This add-in provides a comprehensive UI to manage build configurations, merging, and using pre-build and post-build tasks with MSBuild.


I will update everytime I need a new command or tool. Thank you

Wednesday, March 3, 2010

ASP.NET Shortcut Keys

Technology
ASP.Net & Javascript
Introduction
There are several reasons why you may want to capture the key press event in a browser window. Looking for something like that means that you work as a professional. We will see how you can achive that in internet explorer.
Key codes
In the beginning we will see a list of most used keys with related IE key codes:
  • Alphabetic keys (A~Z): ASCII code of uppercase version of the letter 65 to 90
  • Space : 32
  • Enter : 13
  • Tab : 9
  • ESC : 27
  • Backspace : 8
  • Shit : 16
  • Control : 17
  • Alt : 18
  • Caps : 20
  • Num : 144
  • 0 ~ 9 : 48 ~ 57
  • Left : 37
  • Up : 38
  • Right : 39
  • Down : 40
  • F1 ~ F12 : 112 ~ 123 (I want here to tell you a note about F1)

Implementation
// javascript code
document.onkeyup = KeyCheck;
function KeyCheck(){var KeyID = event.keyCode;switch(KeyID){ .... }

Notes

If you want to catch a function Keys F1 ~ F10

IE events will still be applied for that F key for example F5 will refresh the page.

in this case you have to add the following lines to prevent passing the event to IE :

event.keyCode = 0;

event.returnValue = false;

in case of F1 :

if(document.onhelp == null)

document.onhelp = function() { return false; }

The above is only works for IE

Comments and Questions are welcomed

Tuesday, March 2, 2010

The GridView 'GridViewID' fired event PageIndexChanging which wasn't handled Problem

Technology
- ASP.NET

Problem Description
If you set AllowPaging="true" on a GridView control without using a DataSourceControl DataSource (i.e. SqlDataSource, ObjectDataSource), you will find an error when changing the page on the GridView control:
The GridView 'GridViewID' fired event PageIndexChanging which wasn't handled.


Solution
All what you need here is to handele PageIndexChanging event , then reassign the new page index to the grid page index and finally rebind your grid again as it will loses the datasource binding.
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridView.PageIndex = e.NewPageIndex;
//rebind the Data grid here after assigning the datasource again
}

Finally
You are supposed the find the same problem on sorting as well.
So you have to set the Sort Property of the grid with both direction and expression in the handler of Sorting event of the grid.
Sorting event will be raised by calling the sort method of the grid in server side after handling the click event of each link in the grid header.

Welcome to Questions and Comments ...

Monday, March 1, 2010

MVC Drop down list Problem with Form Post-back
Problem Description

“In Form post-back a drop down list with multiple selection selects only the first option in the drop down list although a view data of multiple selected values is posted to the page”.

Detailed Description
There is a problem of using a drop down list with “multiple = ‘true’“ attribute to have a multi-select drop down list using jQuery Dropdown Check List inside an Html Form.
I think that many of JQuery users would use it as it transforms a regular select html element into a dropdown checkbox list specially for multiple selections.

In aspx page I have something like this inside an Html form :

<%= Html.DropDownList("Modality", ViewData["ModalityList"] as MultiSelectList, new { id = "drpModality" })%>

This drop down list was used as a search header with a ‘Search’ submit button.

MultiSelectList selectionList = new MultiSelectList(selectListItems, "Value", "Text", SearchFields.StudyManager.Modality);
ViewData["ModalityList"] = selectionList;

I sent a ViewData["ModalityList"] from my controller to the page in the post back when search button clicked.
The problem is that the drop down list selects only the first item of the selections !!
After googling I found no solution for that problem and finally I resolved it.

Solution
The solution was very easy and effective. I only changed the drop down list to be a list box and it works perfectly.

<%= Html.DropDownList("Modality", ViewData["ModalityList"] as MultiSelectList, new { id = "drpModality" })%>

It seems that this is a bug ,but thanks to GOD I resolved it.
Any comments or questions are appreciated.