Archive for the 'development' Category
Variable number of digits after the decimal point
Recently I had to format a decimal number to have at least 2 numbers after the decimal point. No big deal. Just use this format for string.Format - “{0:.00}”. But the tricky part was to show more numbers after the decimal point if available. Here is some possible combinations:
|
Decimal |
Desired Output |
Hmm… Do I need to write custom logic to handle all these cases?
No!
Here is the format you can use to achieve the desired result - “{0:.00##}”. This way everything gets formatted properly, and, as added benefit, all decimals that have more than 4 digits after the decimal point get rounded properly.
Quick and elegant!
No commentsEntity Mapping in ADO.NET vNext
Straight from the horse’s mouth - Entity Mapping in ADO.NET vNext
No commentsWorking with hidden variables in ASP.NET 1.1 and 2.0
While working on an ASP.NET page I had to read and write some hidden variables in my code behind.
I figured I could use the following:
Page.RegisterHiddenField(”test”, “testvalue”);
This would create a hidden variable in my HTML which I should be able to access with JavaScript like this:
document.getElementById(’test’).value
The task seemed easy, and I figured it would take around 10 minutes to get everything working. Only there was one problem. The hidden field was rendered like this:
<input type=”hidden” value=”testvalue” />
What is the problem here? Id and/or name are missing! And because of it, I cannot access this variable in my JavaScript.
What is the solution? Use HtmlInputHidden. Here is how to use it.
<input type=”hidden” id=”test” runat=”server” />
And in your code-behind you can assign correct values:
test.Value = “testvalue”
Make sure that the HtmlInputHidden is registered.
protected HtmlInputHidden test;
Now, I encountered this problem in ASP.NET 1.1; In ASP.NET 2.0 this problem has been resolved. Using Page.RegisterHiddenField will produce something similar to this:
<input id=”test” name=”test” type=”hidden” value=”testvalue” />
But, Page.RegisterHiddenField is marked as obsolete, so you can still use it, but it is not recommended. What is the recommended solution?
ClientScriptManager.RegisterHiddenField(string hiddenFieldName, string hiddenFieldInitialValue)
This is the recommended way to work with hidden variables in ASP.NET 2.0. To find out more information - http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerhiddenfield.aspx
2 commentsCode Access Security - It is not easy…
While preparing for 70-536 I finally approached the topic of code access security and, just like I feared, it is not easy. No wonder it didn’t get the wide adoption that Microsoft hoped for. CAS does not fall into pit of success. It is much easier to do the wrong thing as opposed to being very easy to do the right thing.
While looking for more info on CAS I found this good post that clarified some of the things for me. Maybe it will help you as well.
No commentsSubSonic - The Zero Code DAL
I have blogged earlier about Streamlined. Streamlined is a great way to very quickly create admin portion of the site in Rails. Well, it seems like .net and asp.net people are trying to achieve similar results.
Meet SubSonic. It used be known as ASP.NET ActionPack, but recently it was renamed to SubSonic.
Subsonic helps you create DAL classes and UI in ASP.NET. It looks very promising and I can’t wait to try it out in my project.
SubSonic support SQL Server, MySql and Enterprise Library. It works only with ASP.NET 2.0
No commentsList of tools for PowerShell
secretGeek is at it again. He has a great list of tools for PowerShell here. Thank you for a wonderfull post.
1 commentList of TFS tools on CodePlex
Buck Hodges has a good list of TFS tools on CodePlex.
No commentsMicroformats – What is it and why do I need them?
There was a lot of talk recently about microformats. Things like these really intrigue me, so I had to learn more about them.
What is a microformat? It is way to markup certain types of information with the help of HTML attributes, so it is understandable to computers.
Ok, so it is just like XML? Well, not quite. It is very loosely coupled and marked with HTML attributes like these: class, rel and rev.
Aha, I see what you mean… What kind of data can I mark with microformats? I am glad you asked. You can really format any kind of data that is specific to you. Certain types of information are applicable to different industries, so they already have markup defined for them. For example: events, contact information, relationships to other people and others.
Very interesting microformat is rel=”nofollow”. This format tells search engines whether to use this link in determining PageRank or not. There is a really good post that describes how Google works with this format.
All these examples are only beginning of the massive adoption of microformats. I can see how it will be used to markup source code, stock quotes, opinions about certain sites (think trackbacks on steroids), photos, geo location and of course geo tagging.
Ok, all this theoretical stuff is very interesting, but how do I really use this stuff? Here is an example of my contact information marked up with a microformat:
1: <div class="vcard">
2: <a class="url fn n" href="http://www.sashasydoruk.com/">
3: <span class="given-name">Sasha</span>
4: <span class="family-name">Sydoruk</span>
5: </a>
6: <div class="org"><span class="organization-name">ACME Corp.</span></div>
7: </div>
and in html it will look like this:
Scott Hanselman has a good post describing implementation of microsummaries and how it is implemented in dasBlog. In his post he mentions that Firefox 2.0 uses microsummary as a description for all the pages that you add to your Favorites. Another example of tools using microformats is Firefox extension Tails. Tails is a microformat reader; everytime it detects a microformat on a page an icon in the traybar lights up and gives you a nice visual view of all detected entities.
Opportunities for microformats are unlimited and I am really interested to see how they evolve.
DHH respondes to Joel Spolsky’s remarks about Ruby and Rails
or using Digg terminology - Joel vs DHH smackdown!!!
If you didn’t read Joel Spolsky’s “Language Wars”, please read it now. And now go read DHH’s response to the article - Fear, Uncertain, and Doubt by Joel Spolsky.
I happen to like both technologies involved in the smackdown. ASP.NET and C# pay my mortgage and Rails is really enjoyable to work with and I am planning to spend more time learning it.
Currently I am concentrating on C# because I am studying for MCTS 70-536 - .NET Framework 2.0 Application Development Foundation, but when “Agile Web Development with Rails—Second Edition” comes out - I will buy it.
I am very interested to see how this story develops…
No commentsGreat article on language wars from Joel Spolsky
I see this debate coming up all the time. People will spend a lot of time arguing benefits of certain tools and languages instead of actually working on the project. Did I say people? I meant me. I spent huge amount of time trying to decide whether to write a web site in Ruby On Rails or ASP.NET that it is not even funny any more.The outcome?
Finally, I decided on ASP.NET 2.0; but I did waste a couple of months going back and forth between two environments. The good thing the project was my own pet project so the delay this big was not a problem.
The article also highlights the language choices for Copilot - C#, ASP.NET and C++ for Windows Client. But what is even more interesting is the development environment for FogBugz - Wasabi.
“FogBugz is written in Wasabi, a very advanced, functional-programming dialect of Basic with closures and lambdas and Rails-like active records that can be compiled down to VBScript, JavaScript, PHP4 or PHP5. Wasabi is a private, in-house language written by one of our best developers that is optimized specifically for developing FogBugz; the Wasabi compiler itself is written in C#.”
I think Joel mentioned this before.
Anyways, the article is really great, just like everything else from Joel. You might not agree with everything Joel preaches, but he definitely makes you think twice about the things you always took for granted. Go read the article - Joel on Software
No comments