Sub Main(ByVal args() As String) Dim arr() As String = { "3", "1", "6", "10", "5", "13" } For Each num In arr.OrderBy(Function(x) Integer.Parse(x)) Console.WriteLine(num) Next num Console.ReadLine() End Sub
I was recently asked a question. How to prevent a link from triggering if a condition is not met. Here’s a very simple code to do so. If the values of two textboxes do not match, the link does not get clicked. If the values match, the user is navigated to the URL the link points to.
When it comes to Validation using jQuery, the jQuery Validation Plugin is my obvious choice. This plugin provides you with a number of pre-built validation logic. However if you need to build a custom validation method of your own, then here’s how to do so.
In the code shown below, we will add a custom validation method that checks to see if the Age entered is greater than 18. Please see that this is just a demonstration, so feel free to replace the code with a validation logic of your own
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Quickly validate a field in jQuery</title> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"> </script> <script type="text/javascript" src= "http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"> </script> <script type="text/javascript"> $(function() { $.validator.addMethod('AgeGrtrEighteen', function(value) { return parseFloat(value) > 0; }, 'Age has to be greater than 18');
Now when you go ahead and enter a number less than 18 or a negative number in the field and submit the form, you get a validation error message as shown below:
Microsoft Enterprise Library is a popular collection of reusable software components (called application blocks) designed to address common cross-cutting concerns of enterprise application developers (such as logging, validation, data access, exception handling, and more). Entlib is provided as source code, test cases, and documentation that can be used "as is" or extended, and encapsulates the Microsoft recommended and proven practices for .NET application development.
In the code above, we select all the paragraphs and then apply a filter based on the CSS properties set. The code adds a black border around a paragraph whose background color is red and height is 100px
I recently saw a question on the forums where the user needed to pass the value of multiple textboxes while performing an async HTTP request using $.Ajax()
Here’s how to pass the values of multiple textboxes in the $.Ajax() call. The call is being made to an ASP.NET WebMethod which accepts 3 parameters.
A couple of days ago, I was updating my FaceBook account with the pictures I took during my TechEd 2010 visit. The images were of high resolution and there were around 120 of them. I wanted a tool that could easily resize these images.
On searching the net, I found a free tool called Image Resizer. Image Resizer is a clone of the Image Resizer Powertoy for Windows XP -- a PowerToy that allows you to right-click on one or more image files in Windows Explorer to resize them. It was created to extend support to non-XP and 64-bit versions of Windows (including 2000, Vista & 7).
After installing this power toy, all I had to do was right click on the image and choose the ‘Resize Pictures’ option
Clicking it popped up a dialog box
Then I chose the size I wanted and the results were smaller resized images! You can also select all the images in a folder and resize them at once!
The Silverlight 4 Training Course includes a whitepaper that explains all of the new Silverlight 4 features, several hands-on-labs that explain the features, and a 8 unit course for building business applications with Silverlight 4. The business applications course includes 8 modules with extensive hands on labs as well as 25 accompanying videos that walk you through key aspects of building a business application with Silverlight. Key aspects in this course are working with numerous sandboxed and elevated out of browser features, the new RichTextBox control, implicit styling, webcam, drag and drop, multi touch, validation, authentication, MEF, WCF RIA Services, right mouse click, and much more!
Due to a tight work schedule, I had almost decided not to go to TechEd 2010 held between April 12-14 in Bangalore, India. Well not attending it would have been a big mistake!
Fortunately, my work got over in time and thanks to my MVP Lead Abhishek, he arranged an entry for me at the 11th hour. All MVP’s got a free entry to TechEd – just another reason to become an MVP :)
The event completely rocked! Keynotes, Deep Dive Sessions, Product Announcements, Product Team interactions, Contests, Free MS Exams, Giveaways, MVP Parties, Community Track by MVP’s, Partner Stalls, Demo Extravaganza and not to forget, the endless opportunities of networking with business and technology experts. This event had it all. The TechEd India team did a bang-up job to keep everything in perspective and make this event a success.
I bet most of the TechEd attendees are now ready for the next wave of technology innovations and trends. This is one grand daddy of all events no one would want to miss!
Pictures speak larger than words, so I will let some pictures do the talking now! Thanks to Arjit Basu for clicking them.
Check this video of MVP’s at the launch of Visual Studio 2010. I am the one at the beginning of this video wearing a Black T-Shirt and speaking about why developers should attend this event!
What happens when you have text that does not fit its container? Let’s see.
<Grid x:Name="LayoutRoot" Background="White" Margin="40"> <TextBlock Name="tb" Height="20" HorizontalAlignment="Left" Text="This sentence is too long to fit in here" Width="100"> </Grid>
If you run the application, you will observe that the text gets chopped off when it overflows the edge of its container.
To resolve this issue, you could either use the TextWrapping option to wrap the text or instead visually depict that the text is too big for its container. We usually depict this using the trailing three ellipsis(…)
Silverlight 4 introduces the TextTrimming property which adds an ellipses(…) when the text overflows the edge of its container. Here’s how to use this property.
<Grid x:Name="LayoutRoot" Background="White" Margin="40"> <TextBlock Name="tb" Height="20" HorizontalAlignment="Left" Text="This sentence is too long to fit in here" Width="100" TextTrimming="WordEllipsis"/> </Grid>
Now running the same piece of code with the TextTrimming property will produce this output with the trailing ellipses
As defined in Wikipedia – “An Online rich-text editor presents a ‘what-you-see-is-what-you-get’ interface for editing rich text within web browsers. The aim is to reduce the learning curve associated with users trying to express their formatting directly as valid HTML markup.”
I was looking out for a few Rich Text Editors built on top of jQuery and here’s a compilation of the ones I found.
jHtmlArea - A simple, light weight, extensible WYSIWYG HTML Editor built on top of jQuery.
markItUp - markItUp! is a JavaScript plugin built on the jQuery library. It allows you to turn any textarea into a markup editor.
jWYSIWYG - This plugin is an inline content editor to allow editing rich HTML content on the fly.
CSS3 jQuery Rich Text Editor - A web based rich text editorwritten usingjQuery and CSS3 that supports embedded fonts
HTMLBox - HtmlBox is a modern, crossÐ’ browser, interactive, openÐ’ source wysiwyg editor built on top of the excellent JQuery library
If you know of any other editors built using jQuery, let me know via the comments section.
You can now download the reference cards (available as print ready pdf’s) for the default keybindings in Visual Studio 2010 for Visual Basic, Visual C#, Visual C++ and Visual F# over here
Here’s a sample of the Visual C# Keyboard Shortcut Poster
Note: If you have installed Silverlight 4 Beta/RC on your machine, then you have to uninstall the “Update for Visual Studio 2010 (KB976272)” from Add/Remove Programs before installing Silverlight Tools RC2.
What’s New in Silverlight 4
Here are some links that will get you started with Silverlight 4
I was investigating a virtual address space fragmentation issue and came across a tool called VMMap. VMMap is a process virtual and physical memory analysis utility from Sysinternals
To quote from the site “It shows a breakdown of a process's committed virtual memory types as well as the amount of physical memory (working set) assigned by the operating system to those types. Besides graphical representations of memory usage, VMMap also shows summary information and a detailed process memory map. Powerful filtering and refresh capabilities allow you to identify the sources of process memory usage and the memory cost of application features.”
If you are a developer, you should certainly download this tool to understand detailed memory usage per process and optimize your application's memory resource usage. Here’s a sample screenshot
I am here at TechEd India 2010 and am excited to let you all know that Microsoft today released Visual Studio 2010 RTM and .NET Framework 4.0. “I am very excited to announce the availability of Visual Studio 2010 and .NET Framework 4 on April 12th”, Somasegar said.
MSDN Subscribers can download the RTM using the following links
If you thought this was the only exciting news for this week, then there’s more! Today during the keynote at TechEd India 2010, Somasegar announced that Silverlight 4 RTW will be available later this week along with tooling support for Visual Studio 2010
I recently came across a handy utility on Codeplex called Windows Live Writer Backup (WLWBackup). WLWBackup is a backup utility for Windows Live Writer. It backs up blog settings, posts and plugins.
This tool is useful if you plan to change your machine and need to take a back up of your Live Writer. You need .NET 3.5 SP1 on this machine.
Here is a simple tutorial that shows Backing Up and Restoring your settings, posts and plugins.
If you have a bunch of hyperlinks on the page and you try opening them by using $(“a”).click(), they won’t open. This is because you need to first define a click event on that element.
Here’s a solution (shared originally by Owen) that works:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Open all Hyperlinks at Once</title> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"> </script> <script type="text/javascript"> $(function() { $("#open").click(function() { $("a").click(); });
I am glad that I will be attending TechEd India 2010. If you are attending too, make sure you drop by to say a hello! You can recognize me through my profile picture. If you are a regular visitor of my other site www.dotnetcurry.com, you must be familiar with Subodh, Shoban and Mahesh. They too will be around and would be glad to meet DotNetCurry readers!
Microsoft Tech.Ed, the largest technology conclave,is being held in Bangalore, India between April 12-14, 2010! Tech.Ed is an amazing event that introduces you to today's cutting-edge trends and gives you a whirlwind tour of the latest Microsoft technologies.
A very useful jQuery function is the $.unique() that removes all duplicate elements from an array of DOM elements. However this function only works on arrays of DOM elements, not strings or numbers. Thanks to an anonymous reader for pointing this out in the comments section. Here's an updated code on how to remove duplicate elements from an array of integers.
// Original function by Alien51 Array.prototype.unique = function () { var arrVal = this; var uniqueArr = []; for (var i = arrVal.length; i--; ) { var val = arrVal[i]; if ($.inArray(val, uniqueArr) === -1) { uniqueArr.unshift(val); } } return uniqueArr; }
The Array.prototype extends the definition of the array by adding properties and methods. Here we have created a custom function called unique which removes duplicates from an array.
Note: In case of a string array, the search is case-sensitive. So the function does not consider “Put” and “put” as duplicate
I have been asked this question a couple of times and the answer is that Visual Studio 2010 RC expires on June 30, 2010. Microsoft says “ We will give you plenty of time after our announced April 12th launch to upgrade to final RTM bits before the RC build expires”
You can also check the number of days left for the RC to expire by going to Help > About Visual Studio
I got a mail from a devcurry.com reader Martin this morning who asks me “I have a string containing XML tags and I need to create a XML document out of it without much efforts. Is there an easy way to do so. I can assure that the string contains valid xml”
Yes Martin, there is an easy way to do so. You have to use the XDocument.Parse() method. Here’s an example. Add a reference to System.Xml.Linq and write the following code in a console application
Sub Main(ByVal args() As String) Dim s As String = "<?xml version=""1.0""?>" & ControlChars.CrLf & _ " <Country name=""India"">" & ControlChars.CrLf & _ " <Capital>New Delhi</Capital>" & ControlChars.CrLf & " </Country>" ' preserve whitespaces Dim xDoc As XDocument = XDocument.Parse(s, LoadOptions.PreserveWhitespace) Console.WriteLine(xDoc) Console.ReadLine() End Sub
Here’s a simple script that sums up all textbox values using jQuery. Please note that I am not using any validation here to validate the data entered. The script simply shows how to sum up textbox values.
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sum of all TextBox values using jQuery</title> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"> </script> <script type="text/javascript"> $(function() { $("#addAll").click(function() { var add = 0; $(".amt").each(function() { add += Number($(this).val()); }); $("#para").text("Sum of all textboxes is : " + add); }); }); </script> </head> <body> <input id="Text1" class="amt" type="text" /><br /> <input id="Text2" class="amt" type="text" /><br /> <input id="Text3" class="amt" type="text" /><br /> <input id="addAll" type="button" value="Sum all Textboxes" /><br /> <p id="para" /> </body> </html>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim str As String = "Some sample <b>string</b> to <i>test</i>" Response.Write("Before Encoding : " & str) Response.Write("<br/>") Dim sw As New StringWriter() Server.HtmlEncode(str, sw) Dim htmlEncStr As String = sw.ToString() Response.Write("After Encoding : " & htmlEncStr) End Sub
I got excited when I heard that Charlez Petzold is authoring a Book called “Programming Windows Phone 7 Series”. To add icing to the cake, he is already offering a draft preview of his eBook FREE of cost!
This preview ebook contains six chapters in three parts (153 pages total). Get more details over here
You can download the eBook in PDF and XPS format over here
Visual Studio Team System MVP Subodh Sohoni has been writing some amazing articles on Visual Studio Team System and Test Professional 2010. Here are some of them in case you haven’t read them already
Quoted - “This Windows Phone 7 Training Kit will give you a jumpstart into the new Windows Phone world by providing you with a step-by-step explanation of the tools to use and some key concepts for programming Windows Phones”
Audience Prerequisites:
This training kit is geared for beginners who want to get started with developing applications for the latest Windows Phone operating system. Even if you don’t know Silverlight or XNA Framework, you’ll find this Training Kit useful. More seasoned Silverlight developers should also find this kit useful, as it explains some of the differences between Silverlight and Silverlight for the phone.