Tuesday, December 9, 2008

Custom Verbs in your Webparts

Here I would shoud you how I added custom verbs in my custom webpart.

Override
WebPartVerbCollection
property in your webpart class and provide the following implementation

public override WebPartVerbCollection Verbs

{

get

{

WebPartVerb verb = new WebPartVerb("ExportToList", ExportToList); //New Verb

verb.Text = "Save Data to List"; //Text for Verb

WebPartVerb[] newVerbs = new WebPartVerb[] { verb }; //Add the verb into the array

//Add the array of verbs to the collection

WebPartVerbCollection verbs = new WebPartVerbCollection(base.Verbs, newVerbs);

return verbs;

}

}



Here First I am declaring new verb that we want, in the next line I am assigning Text to it.
Then I am declaring an array to contain this new verb and finally add this very to the base Verbs collection and return that collection.

When we declare verb, in the constructor second argument is the Handller event (e.g. ExportToList) which will be fired when this verb is clicked from your webpart.

We need to implement that Handler in our code and we can write actions which we want in that as given below:

public void ExportToList(object sender, WebPartEventArgs e)
{
// Add the logic to export this list
}


With above two implementations, when you deploy this webpart, you would see that verb in your webpart.

Cheers,


Steps for Setting up New Virtual Machine


- Install Virtual Server 2005 Software on the Host system
- Once installed, Open up Virtual Server Administrative Site from Programs
menu
- Create new Virtual Machine
1. Name it,
2. Set hardware config - RAM, Space, Network Adapters
- Insert Windows Server 2003 Installation Disk
O.S. Installation will proceed
- Keep on installing required Software on the virtual machine along with Service Packs needed.
- Setup the virtual machine to be in Domain

Note: Points to remember to Remote desktop to virtual machine
Control Panel > Add Hardware > Install the hardware that I manuall select from the list
From the list, Select Network Adapters, Next Select Microsoft as Manufacturer and from right select Loopback adapter. and proceed to Install.
Next go to Virtual Server Administrative site and configure your Virtual machine to add new Network adapter and restart the machine.

Now you should be able to login to the new virtual machine and start development.

Happy development..