Monday, June 29, 2009

Hidden Columns with values: asp:GridView (access the value of the hidden columns in gridview )

If you set Column Visible property to false, this column won't rendered. But if you want these values available, What will you do?

My trick was, set HeaderText to empty, convert the BoundField in TemplateField, and use a HiddenField control. The effect the column won't be visible. Also you can use the controls array to access to value property.

<columns><asp:boundfield datafield="CompanyCode" headertext="Company" sortexpression="CompanyCode">
...
<columns>
<asp:templatefield><itemtemplate><asp:hiddenfield id="hf1" value="">">
runat="server"></asp:hiddenfield></itemtemplate>
...
// accesing the value property
int tmpID =
Convert.ToInt32(((HiddenField)GridView1.SelectedRow.Cells[3].Controls[1]).Value); </asp:templatefield></columns></asp:boundfield></columns>

Tuesday, June 23, 2009

How to add link to a css file in content page

Try this

In VB

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim css As HtmlGenericControl
css = New HtmlGenericControl
css.TagName = "style"
css.Attributes.Add("type", "text/css")
css.InnerHtml = "@import ""/foobar.css"";"
Page.Header.Controls.Add(css)
End Sub

In C#

protected void Page_Init(object sender, System.EventArgs e)
{
HtmlGenericControl css;
css = new HtmlGenericControl();
css.TagName = "style";
css.Attributes.Add("type", "text/css");
css.InnerHtml = "@import \"/foobar.css\";";
Page.Header.Controls.Add(css);
}

How To Validate a Serial Number During an Installation Created with VSI

How To Validate a Serial Number During an Installation Created with VSI


SUMMARY
In a Visual Studio Installer (VSI) project, the developer has the ability to ad...

In a Visual Studio Installer (VSI) project, the developer has the ability to add a Customer Information dialog box in the user interface. By default, this dialog box has an input field for a serial number. Visual Studio Installer provides minimal support for validating this field. This article provides the steps necessary to include custom code to validate the serial number that is entered by the user. These steps include using the Windows Installer SDK tool Orca, and creating a DLL for which sample code is provided.

To download the Orca tool, see the following MSDN Web site that includes samples, tools, and documentation for the Windows Installer
http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/457/msdncompositedoc.xml (http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/457/msdncompositedoc.xml)

MORE INFORMATION
Create an empty installer project with VSI.Add a Customer Information dialog box...

  1. Create an empty installer project with VSI.
  2. Add a Customer Information dialog box to the user interface. Do not change the default properties for the dialog box.
  3. Build the project.
  4. Create a custom action DLL. NOTE: You cannot use an EXE custom action because this custom action sets a property and that can only be accomplished by using a DLL, which has a handle to the installation.

  5. On the Tools menu, click the Options Directories tab in your DLL project, and then add the path to the Windows Installer SDK's Include and Lib directories.
  6. In the Project Settings dialog box, add msi.lib to the library list. Use either a .DEF file or the __declspec(dllimport) attribute to export the DLL functions. Note that the PIDKEY property has the value of "XXX -XXXXXXX" where X is a number and there is both a space and hyphen. The following sample code uses a string comparison to determine if the serial number is valid:
    UINT __stdcall VerifyPID(MSIHANDLE hInstall)
    {
    // Local variables
    UINT nRetVal = 0;
    UINT uiMsiRc;
    TCHAR szPidKey[MAX_PATH];
    DWORD dwBuffer;

    dwBuffer = sizeof(szPidKey)/sizeof(TCHAR);

    // First Step - Get the PIDKEY property
    uiMsiRc = MsiGetProperty(hInstall, TEXT("PIDKEY"), szPidKey, &dwBuffer);

    if (ERROR_SUCCESS != uiMsiRc)
    {
    MessageBox(NULL, "PIDKEY", "Not able to retrieve PIDKEY property", MB_OK | MB_ICONEXCLAMATION);
    return 0;
    }

    //Insert code to check PIDKEY here
    int str = lstrcmp(szPidKey, "123 -4567890");

    //If PIDKEY passes check
    if (str == 0)
    MsiSetProperty(hInstall, "PIDCHECK", "TRUE");
    //If PIDKEY doesn't pass check
    else
    {
    MsiSetProperty(hInstall, "PIDCHECK", "FALSE");
    wsprintf(szText, "Please enter the correct code");
    MessageBox(NULL, szText, "PIDCHECK", MB_OK | MB_ICONINFORMATION);
    }

    return 0;
    }
  7. Open the Microsoft Windows installer package (.msi) file that you built with VSI in Orca.
  8. Add the DLL to the Binary table and name it VerifyPIDDll.
  9. Add a new custom action to the Custom Action Table:
    Name - MyPIDChecker;
    Type - 1; Source - VerifyPIDDll; Target - VerifyPID
  10. In the ControlEvent table, find the UserNameForm, which corresponds to the Customer Information dialog box from VSI. Make all changes to the existing rows with UserNameForm in the Dialog column and Next in the Control column:
    1. Replace the ValidateProductID Event with DoAction. On the same row, replace the Argument {} with MyPIDChecker.
    2. Make sure that the value for the Condition column in the row with the EndDialog event is:
      UserNameForm_NextArgs="" AND UserNameForm_ShowSerial=""
    3. Using the PIDCHECK property which was set in the precious sample code, make sure that the value for the Condition column in the row with the NewDialog event is:
      (PIDCHECK="TRUE") AND UserNameForm_NextArgs<>"" AND UserNameForm_ShowSerial<>""
    4. Make sure that the value for the Condition column in the row with the [UserNameForm_ShowSerialDisabled] event is:
      PIDCHECK="TRUE"
  11. Save the .msi file and run the installation.

Deploy your Application or Component Using Windows Installer and serial key

Introduction

When ever we heard about deployment of our application or component we get scared with the traditional scripted setup programs. The main goal of this article is to make .NET programmers to get used to this easy to setup program which allows you to deploy your application even if you don't know how to write the setup script. Microsoft Dot Net Setup & Deployment will make the setup for you with simple clicks. It is also provided with self taught easy driven wizards. Many programmers who are using Microsoft Visual Studio Dot Net they are not fully aware of this windows installer that comes with Visual Studio; they are going for other setup programs that need's hard scripting knowledge. Using Windows Installer is very easy.

About Microsoft Windows Installer

Windows Installer enables you to deploy your Applications and Components in an efficient manner. The installer provides new capabilities to advertise features without installing them, to install products on demand, and to add user customizations. Windows Installer is an installation and configuration service that reduces the total cost of ownership. The installer enables customers to better address corporate deployment and provide a standard format for component management.

Run-Time Requirements

This technology is available as a redistributable for Windows Installer version 2.0, from the Microsoft Downloads.

Features of Windows Installer:

> It is based on a data-driven model that provides all installation data and instructions in a single package. In contrast, traditional scripted setup programs. > It also supports self-repair � the ability for an application to automatically reinstall. > It provides the ability to roll back an installation. The deployment tools in Visual Studio .NET build on the foundation of Windows Installer, providing you with rich capabilities for rapidly deploying and maintaining applications built with Visual Studio .NET. Creating your first Deployment Project Visual Studio provides templates for four types of deployment projects: Setup Project Builds an installer for a Windows-based application. Merge Module Project (.msm) is used to pack components that might be shared by multiple applications. Web Setup Project Builds an installer for a Web application. Cab Project (.cab) Creates a cabinet file for downloading to a legacy Web Browser In addition, a Setup wizard is provided to help step you through the process of creating deployment projects.
  • For a Setup project, the installer will install files into a Program Files directory on a target computer.
  • For a Web Setup project, the installer will install files into a Virtual Root directory on a Web server.
Note If you have created a standard deployment project and later decide to deploy it to a Web, you will need to create a new project.

Five Easy Steps:

Step 1

Open the Visual Studio IDE, and select File->New ->Setup and Deployment Projects. Select the Setup Wizard. Give the File name and location where to store that project as shown in the below figure.

Step 2

Welcome to Setup Project Wizard will appear. It is a simple Four Steps Wizard. Click on the Next Button. In the second step on the wizard it will ask the type of the setup. Choose appropriate here I has chosen setup for windows application and click Next.

Step 3

In the third step of this wizard it will ask to add your developed application or component and other files that you need to place in the clients machine, for example say documentation files

Now It will display as shown below figure.

Step 4

As you can see in above figure, The application folder is the folder where your application and supported files will be installed. User's Desktop and Programs Menu are the clients desktop and programs menus respectively. If Place the short files of your main application & Help files on the user's desktop and programs menu, then during the installation the application, supported files and the shortcuts will be placed automatically as you directed by placing the intended files in Application, User Desktop directories and programs menu.

We can use the following editors during the deployment of our application

You can find these editiors in the solution explorer each as a button as shown below,

File System Editor:

It allows you to add project outputs, files, and other items to a deployment project and specify where they will be installed on the target computer.

Registry Settings Management Editor:

Allows you to specify registry keys and values to be added to the registry of the target computer.

File Types Management Editor :

It is used to establish file associations on the target computer.

Custom Actions Management Editor

Allows you to specify additional actions to be performed on the target computer at the end of an installation.

Launch Condition Management Editor :

Allows you to specify conditions that must be met in order to successfully run an installation.

User Interface Management Editor

As shown in above figure, User InterfaceManagement Editor is used to specify and set properties for predefined dialog boxes that are displayed duging the installation on the target system.

The Customer Information Dialog is important to protect your software.

for that first set the Show SerialNumber property to true ( false by default).

there will be a template for the serial key called SerialNumberTemplate:-

Valid editable characters for the SerialNumberTemplate property are:

Character Meaning

#

Requires a digit that will not be included in the validation algorithm.

%

Requires a digit that will be included in the validation algorithm.

?

Requires an alphanumeric character that will not be included in the validation algorithm.

^

Requires an uppercase or lowercase character. Numeric digits are not valid here.

<

Any characters to the left of this character will not be visible in the dialog box.

>

Any characters to the right of this character will not be visible in the dialog box. Required as a terminator if the <>

note that any other character is treated as a literal constant.

The Default template is <###-%%%%%%%>, Which create two text boxes separated by a dash surrounded by spaces.

The first has # which means that use must enter three numbers but those numbers will not be participating in the validation algorithm.

The Second box had seven digits,

% means that it will be involving in the validation. we apply modulo 7 to the sum of these required digits and if it equate to 0 algorithm returns true and the user can proceed to next dialog box.

Example:-

<###-%%%%%%%>,

124 - 7134501 is one of the key by which the user can proceed to next dialog box.

the first three digits 1, 2 and 4 can be any digits as they will not participate in validation.

the next seven digits 7134501 when you sum them you will get 21 and if you apply 21%7 you will get 0 so this is ok. Like wise you have to proceed.

You can add the dialog boxes like end user license agreement dialog and serial key dialog as shown.

Step 5

When you build the application, you will find the install program for your software or component in the projects debug directory.

Conclusion

I hope that many of the .Net developers who are using traditional setup script programs will find this as a easy and simple way to deploy your software. More than that if you got the licensed Visual Studio .Net with you then there is no need to purchase setup applications from other companies as Visual Studio .Net itself offers it for you. I think that I had given enough features of Windows Installer that comes with Visual Studio .Net. Now it's time that you try it just once to get used to it.

Wednesday, June 10, 2009

Javascript function to make asp.net control invisible

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<script type="text/javascript" language="javascript">

function clearingTheLabels()

{

document.body.style.cursor = 'wait';

var lblGoodbad1='<%=lbtGoodBadStatus.ClientID %>';

var lblwordCount='<%=lblWordCount.ClientID %>';

document.getElementById(lblGoodbad1).style.visibility="hidden";

document.getElementById(lblwordCount).style.visibility="hidden";

document.getElementById('<%=grdScorer.ClientID %>').style.visibility="hidden";

}

script>


In Code behind

btnUrlToCrawl.Attributes.Add("onclick", "clearingTheLabels();");