vrijdag 25 november 2011

LinkButtons als DefaultButton in ASP.NET

Vaak gebruiken we LinkButtons als alternatief voor 'normale' buttons. Nadeel hiervan is dat je een LinkButton niet als DefaultButton in kunt stellen op een Panel. Daardoor kun je helaas de enter-toets niet gebruiken op die knop.

Zojuist kwam ik hiervoor een oplossing tegen. Je maakt een custom control die overerft van System.Web.UI.WebControls.LinkButton. Deze custom control voegt een stukje javascript toe aan je pagina, waarmee de DefaultButton wél werkt!

using System;
using System.Web.UI;

namespace BISBV.GUI.TemplateControls
{
public class BISBVLinkButton : System.Web.UI.WebControls.LinkButton
{
private const string _addClickScript = "AddDefaultButtonClickFn('{0}');";
private const string _addClickFunctionScript =
@"function AddDefaultButtonClickFn(id) {{
var b = document.getElementById(id);
if (b && typeof(b.click) == 'undefined') b.click = function() {{
var result = true; if (b.onclick) result = b.onclick();
if (typeof(result) == 'undefined' || result) {{ eval(b.getAttribute('href')); }}
}}}};";

protected override void OnLoad(System.EventArgs e)
{
// Registreer de JavaScript-functie voor de DefaultButton.
ScriptManager.RegisterStartupScript(this, this.GetType(), "addClickFunctionScript", _addClickFunctionScript, true);
// Voeg op deze LinkButton een StartupScript toe.
ScriptManager.RegisterStartupScript(
this,
this.GetType(),
"click_" + ClientID,
string.Format(_addClickScript, ClientID),
true);

base.OnLoad(e);
}
}
}

Omdat we ASP.NET AJAX gebruiken worden de stukjes JavaScript geregistreerd via de ScriptManager. Als je geen AJAX gebruikt vervang je dit voor 'ClientScript'.

maandag 7 maart 2011

Creating Mock Web Services in .Net (automated in .proj file)

Ian Dykes heeft een interessant artikel geschreven over hoe je webservices kunt mocken.
http://iandykes.blogspot.com/2008/06/creating-mock-web-services-in-net.html

Mochten de webservices (en dus de wsdl's) veel wijzigen kun je dit automatiseren.

Open je .csproj bestand in Notepad (oid) en verwijder de rond de BeforeBuild target.

Ik plaats de wsdl's in een map genaamd resources en deze worden met onderstaande code automatisch in je project opgenomen.


<ItemGroup>
  <WSDLs Include=\"Resources\\*.wsdl\" />
</ItemGroup>


Standaard kent msbuild het pad naar wsdl.exe niet dus deze even uit het register halen.


<PropertyGroup>
   <WindowsSDKPath>$(registry:HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows@CurrentInstallFolder)</WindowsSDKPath>
</PropertyGroup>


Daarna nog even het beforebuild target aanpassen zodat voordat je solution gebuild word nog even snel de laatste Service interfaces gegenereerd worden.


<Target Name=\"BeforeBuild\">
  <Message Text=\"Updating Web Reference...\" />
  <Exec Command=\"&quot;$(WindowsSDKPath)bin\\wsdl.exe&quot; /nologo /protocol:SOAP /Serverinterface /n:$(RootNamespace) %(WSDLs.Identity)\" />
</Target>

*Deze code kun je ook gebruiken om je proxy-classes automatisch bij te werken (haal /serverinterface en /protocol:SOAP weg en hij genereert proxyclasses.

In je project kun je 1 of meerdere webservices aanmaken die de interface implementeren. Even de functies implementeren en je kunt er tegenaan programmeren.

Een volgende keer een snippet hoe je de input naar een .xml bestand kunt schrijven om te kijken of het klopt. :)

zaterdag 5 maart 2011

Book: Coding Faster: Getting More Productive with Microsoft Visual Studio

Pre-Order for Coding Faster: Getting More Productive with Microsoft Visual Studio is Available

http://blogs.msdn.com/b/zainnab/archive/2011/01/24/pre-order-for-coding-faster-getting-more-productive-with-microsoft-visual-studio-is-available.aspx


Work smarter and increase your productivity with expert tips and tricks for using Microsoft Visual Studio. This quick reference provides practical advice and shortcuts for the code editor, visual designers, search capabilities, debugger, and other features of the IDE through several versions. Get practical insights into how Visual Studio works, whether you're a beginner or an experienced user.
Discover how to:
  • Change development settings and keyboard mappings to optimize your efficiency
  • Understand your options when initiating a new project
  • Use the Editor more effectively with tips on selecting and manipulating code
  • Search your code for references, symbols, and other items
  • Reduce the amount of time you spend debugging your code
  • Create Visual Studio extensions for greater development productivity

About the Author

Zain Naboulsi is a Senior Developer Evangelist at Microsoft® and frequently lectures on Visual Studio® topics.
Sara Ford is a developer evangelist for Microsoft, and author of the Microsoft Press book Microsoft Visual Studio Tips (2008).

vrijdag 4 maart 2011

Windows PowerShell and Visual Studio

  • Om .ps1 bestanden uit te kunnen voeren:
PS > Set-ExecutionPolicy RemoteSigned

  • Notepad++ alias aanmaken

PS > Set-Alias n++ 'C:\Program Files (x86)\Notepad++\notepad++.exe'
  • Je PowerShell profiel aanpassen (met Notepad++)

PS > $test = Test-Path $PROFILE; If($test -eq $false){New-Item -ItemType file -force $PROFILE}Else{n++ $PROFILE}


donderdag 3 maart 2011

Social media howto: Twitter en Facebook

Op KissMetrics staan 2 hele interessante artikels over het implementeren van Facebook in je website en het opzetten van goed Twitter account waarbij de focus ligt op marketing van je product. Zeker de moeite waard als je wat meer wilt weten over Social Media.

Facebook for websites:
http://blog.kissmetrics.com/facebook-social-plugins/

Twitter marketing Guide
http://blog.kissmetrics.com/twitter-marketing-guide/

maandag 28 februari 2011

Visual Studio Productivity Power Tools

Voor de mensen die Visual Studio 2010 gebruiken... Erg handig!!

http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef/
Version: 10.0.11019.3

Solution Navigator  (Updated)
Solution Navigator is a new tool window that acts like an enhanced Solution Explorer

Tab Well UI 
This extension allows you to completely customize the behaviour of your document tabs from the Productivity Power Tools Options

Searchable Add Reference Dialog
The new Add Reference dialog makes it faster and easier for you to find the reference that you are looking for and add it to your VB, C# or F# project

Tools Options Support
The number one feature request by far has been the ability to turn off the individual extensions in the Productivity Power Tools.

Quick Access
Quick Access is a new tool window that allows users to search for and execute common tasks within the Visual Studio IDE.

Auto Brace CompletionAutomatic Brace Completion improves the productivity of writing code by automatically inserting the closing code construct when the opening construct is typed for VB & C#

Highlight Current Line
As the resolution of monitors increases, it’s becoming more difficult to find the caret in the code editor.

HTML Copy
This extension provides support for the HTML Clipboard format when cutting or copying code from the editor.

Triple Click
It’s never been easier to select a line of code from the mouse by simple triple-clicking anywhere on the line.

Fix Mixed Tabs
Some developers prefer tabs, others prefer spaces, and nobody likes mixing tabs & spaces.

Ctrl + Click Go To Definition
This extension gives the editor a web browser by adding clickable hyperlinks to symbols in your code as you hold down the Ctrl key

Align Assignments
This extension is useful for making your code a little more readable by aligning the assignments when you type Ctrl+Alt+]

Move Line Up/Down Commands
This extension maps the Alt+Up Arrow & Alt+Down Arrow keys such that they will move the current line of code or the selected lines up and down through the editor. 

Column Guides
Since Visual Studio 2002, there has been a not so secret registry key which allowed user to draw a vertical line in the code editor.

Colorized Parameter Help
This extension improves consistency with the editor by applying syntax highlighting to the contents of the Parameter Help window for C# &VB.

Via: http://blogs.msdn.com/b/ukmsdn/archive/2011/02/22/visual-studio-2010-productivity-power-tools.aspx

vrijdag 18 februari 2011

Volg ook onze Twitter

Zo, Marco heeft de boel weer even wakker geschud met zijn laatste blog. Hopelijk volgen er weer meer (nu ook weer eens van andere collega's???). Ik zal ook binnenkort weer eens een stukje schrijven. Waar wij als Business Internet Support zijnde wel regelmatig iets interessants neerzetten, is op Twitter. Daarom wil ik jullie in ieder geval verwijzen naar het Twitter account van BIS:

http://www.twitter.com/bisbv

Vergeet ook ons DetacherenDotNet account niet: http://www.twitter.com/detachdotnet

donderdag 17 februari 2011

Tips and Tricks: Clipboard Ring and Toolbox Snippets

Turns out that Visual Studio already has this “hidden” feature. It’s called the Clipboard Ring. If you copy a number of items to the clipboard, pressing [Ctrl]+[Shift]+[V] will paste the last text that was copied, but it will also highlight the pasted phrase. Continue holding down [Ctrl]+[Shift] and press [V] again. This will cause that highlighted section to cycle through the other items on the clipboard. This is extremely useful when you have to copy multiple lines of separate text to a new document.

http://blogs.msdn.com/b/visualstudio/archive/2010/03/10/tips-and-tricks-clipboard-ring-and-toolbox-snippets.aspx