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.