Archive for the '.net' Category
Heroes Happened Here - 2008 is going to be great!
Just got back from the official launch event of Windows Server 2008, Visual Studio 2008 and SQL Server 2008. It was quite amazing to see Steve Ballmer speak. Microsoft has some great plans for the launch products, and to be fair, they do look amazing.
VS 2008 is an amazing product for developing software. And especially now, with ReSharper 4.0 out, I can keep developing with passion.
LINQ, lambda expression, faster VS, better JS debugging - all these together - AWESOME. Now we just need to wait for Silverlight 2 and MVC.
IIS 7 needs to be mentioned by itself. Hosting asp.net applications is going to so nice. I just can’t wait.
What else? I got to see Brad Adams speak. His presentation was nice, but a bit outdated. He mentioned asp.net ajax and ajax toolkit, which are great, but it is kind of old news now. I guess, Mix is where all the great stuff will come out. I mentioned my issues with Silverlight animations, but it didn’t seem like he knew of a fix.
Got to talk to some people from SQL Server team, and those guys were great! If you are their manager, they deserve a raise! SQL Server 2008 has some amazing features and I hope I will get to use it soon.
All in all, a great event, great swag and a lot of really great people.
2008 is going to be a wonderful year for developers!
2 commentsSilverlight - I really wanted to like you, but…
I really want to like Silverlight, but it is really hard to do. The idea is great, but if you look at v1.0 it is… meh…
Tafiti, Popfly and Halo3 banner at microsoft.com are supposed to look nice, but the animation is so jerky, it makes me cry. It looks like a kid having epilepsy. It kills whatever interest I had in the product. Ironically, I spent 3 hours last night reading up on Silverlight and it feels like the time was wasted. Should have played WoW instead. Dino Esposito was absolutely right - Silverlight 1.0 was obsolete before it even came out of beta. Stillborn?
I really hope v1.1 will be absolutely awesome, but as of now - it is embarrassing.
Here is more - http://www.chausse.org/2007/08/tafiti-microsoft-bob-for-search/
Tafiti? who would ever use tafiti if there is Ms. Dewey?
Sad, but true.
No commentsWhere are all the cool startups that run on ASP.NET?
I have been a proud user of .NET framework for 6 years now and I still think it is a really awesome product and Microsoft did a wonderful job developing it.
WinForms is the best way to develop Windows application (with occasional jump into Interop for extra APIs); ASP.NET is enjoyable way to develop web applications and WCF is just pure honey. If all this makes me sound like Micro$oft fanboy, that’s because I am. .NET is really awesome and Visual Studio is the best way to do any kind of development. Especially with Resharper installed. I don’t know how JetBrains did it, but somehow they sold their souls to Satan and in return they can unleash the dark magic of Ctrl+Alt+Space.
But what puzzles me is that not too many people use ASP.NET to create cool products. Sure there are Community Server, MySpace, DotNetKicks and DasBlog; there are all very fine products, but compare them to LAMP, Rails and Java lineup: Digg, Yahoo, LinkedIn, Flickr, Backpack and the Company, Delicious, all the Google Apps, Mint, Meebo, Twitter, Zillow and of course Infinite Cat Project. If you checkout the new startups on TechCrunch, it seems like every new startup is something Linux based and is not ASP.NET.
And I really want to know why. If you are a new startup, you have only one shot at it, so you really want to use the best tools available. And it seems like everybody picks anything but ASP.NET, unless you are doing corporate development.
Why are there so few startups that use ASP.NET? Is it the cost of tools? Hosting cost? Restrictive licensing? Or maybe ASP.NET became “the van” of web development. Safe, bulky and definitely not sexy.
I am sure that I have missed some really awesome ASP.NET projects, so please post the links in comments. Any thoughtful feedback is welcome. All flaming and FUD will be moderated.
43 commentsSafari + AutoComplete Extender + ModalPopup = What the hell?
If you have a bunch of AutoComplete extenders that are wrapped inside of ModalPopup and you try to run it in Safari, chances are, you will not like what you see. The autocomplete div will be shown under the modalpopup. Works fine in Firefox and IE, but Safari is screwed up. What gives?
Well, if you look into source code of AutoComplete extender, you will notice that they have a special handling for Safari (also known as a one-button mouse of the browsers
Just kidding!). Because of this special handling, the correct z-index is not being set on the autocomplete div.
But how can I fix it? Well, all you need to do is to add a div somewhere near the extender with id of “AutoCompleteDiv” and in your extender set the property of CompletionListElementID to “AutoCompleteDiv”.
Here is how I found this info:
- http://logbook.trioro.com/2006/12/ajaxnet-autocompleteextender.html
- http://tim.mackey.ie/ProblemsWithTheAJAXAutoCompleteExtenderArrgh.aspx
Also, there is a custom autocomplete extender based on prototype and script.ac.ulous. I have not tried but it looks really interesting. I would like to take a look the source when I have a bit more time. Here is the link.
No commentsASP.NET AJAX - brilliant or extremely difficult to understand
I just started using ASP.NET AJAX extensively in my work and I am not sure what to make of it. The whole asp.net ajax is pretty complicated once you get away from basic UpdatePanel scenarios. But finally there is a book about it. As always, my hero Dino Esposito came through and wrote a book, so the rest of us can learn how to use it. Book’s name - Introducing Microsoft ASP.NET AJAX.
I got mine from Amazon because bookstores in the hood didn’t have it and I just could not wait anymore. I have been waiting for APRESS’s Foundations of ASP.NET AJAX but it has been delayed so many times that I gave up on that book.
I am 2/3 through the book and so far I like it. It cleared up a lot of misconceptions that I had about asp.net ajax and actually explained in full detail the magic behind UpdatePanel.
I have a pretty good understanding of how different parts of asp.net ajax work, but I still want to see how it all ties up together. Could someone get me the source of PageFlakes?
The last 1/3 of the Dino’s book mentions something about writing ajax enabled applications, but I have not gotten to that part yet..
My Book Rating to Introducing Microsoft ASP.NET AJAX - Good Times!
No comments70-528 - Passed
I passed this exam a month ago, just didn’t have time to write about it. This is my second exam in the .NET certification route and that means that I am officially MCTS now. Fear my power!
I was pleasantly surprised by the study guide and the exam itself. I have been doing asp.net for 5 years now and I still learned some new stuff.
Which proves that everybody should get certified and not for the official MS welcome kit, which is really lame, but to make sure that one has good understanding what .net and asp.net have to offer and not to reinvent the wheel.
No commentsHowTo - CompositeControl with a TextBox and a bunch of Validators
Here is an example of how I create composite controls in small server control library. It is pretty handy. With controls like this you can say something like this:
<csc:textbox id=”customServerControl1″ minlength=”4″ maxlength=”10″ required=”true” runat=”server” />
And that’s it! The composite control will automatically add the required validators and will create appropriate error messages!
Here is the source code:
using System; using System.Security.Permissions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace SashaSydoruk.Web.UI.WebControls { [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [ToolboxData(“< {0}:textbox required=\"false\" runat=\"server\" />“)] [ValidationProperty(“Text”)] public class TextBox : CompositeControl { protected System.Web.UI.WebControls.TextBox _textBox = null; protected RequiredFieldValidator _reqValidator = null; protected RegularExpressionValidator _regExValidator = null; protected TextBoxLengthValidator _lengthValidator = null; protected string _regExValidatorErrorMessage = string.Empty; #region Constructors public TextBox() { EnsureChildControls(); } #endregion #region Error Messages public const string REQUIRED = “is a required field.”; public const string REGEX = “is invalid.”; public const string LENGTH = “length has to be {0} to {1} characters long”; #endregion #region Public Properties public System.Web.UI.WebControls.TextBox InnerTextBox { get { return _textBox; } } public RequiredFieldValidator InnerRequiredFieldValidator { get { return _reqValidator; } } public RegularExpressionValidator InnerRegularExpressionValidator { get { return _regExValidator; } } public TextBoxLengthValidator InnerTextBoxLengthValidator { get { return _lengthValidator; } } public TextBoxMode TextMode { get { return _textBox.TextMode; } set { _textBox.TextMode = value; } } public bool ReadOnly { get { object o = ViewState[“ReadOnly”]; if(o == null) { return false; } else { return bool.Parse(o.ToString()); } } set { ViewState[“ReadOnly”] = value; } } public int MaxLength { get { return _lengthValidator.MaximumLength; } set { _lengthValidator.MaximumLength = value; SetupValidators(); } } public int MinLength { get { return _lengthValidator.MinimumLength; } set { _lengthValidator.MinimumLength = value; SetupValidators(); } } public string RegularExpression { get { return _regExValidator.ValidationExpression; } set { _regExValidator.ValidationExpression = value; SetupValidators(); } } public string DisplayName { get { object o = ViewState[“DisplayName”]; if(o == null) { return string.Empty; } else { return o.ToString(); } } set { ViewState[“DisplayName”] = value; SetupValidators(); } } public bool Required { get { return _reqValidator.Visible; } set { _reqValidator.Visible = value; SetupValidators(); } } public virtual string Text { get { return _textBox.Text; } set { _textBox.Text = value; } } #endregion protected override void OnInit(EventArgs e) { EnsureChildControls(); base.OnInit(e); } protected override void Render(HtmlTextWriter writer) { _textBox.Width = Width; _textBox.Height = Height; _textBox.RenderControl(writer); _reqValidator.RenderControl(writer); _lengthValidator.RenderControl(writer); _regExValidator.RenderControl(writer); } protected override void CreateChildControls() { Controls.Clear(); _textBox = new System.Web.UI.WebControls.TextBox(); _textBox.ID = “textBox”; Controls.Add(_textBox); //Add required validator _reqValidator = new RequiredFieldValidator(); Controls.Add(_reqValidator); //Add length validator _lengthValidator = new TextBoxLengthValidator(); Controls.Add(_lengthValidator); //Add RegularExpression validator _regExValidator = new RegularExpressionValidator(); Controls.Add(_regExValidator); if(Width.Value == 0) { _textBox.Width = Unit.Pixel(170); } Required = false; SetupValidators(); } private void SetupValidators() { _reqValidator.Display = ValidatorDisplay.None; _reqValidator.ControlToValidate = _textBox.ID; _lengthValidator.Display = ValidatorDisplay.None; _lengthValidator.ControlToValidate = _textBox.ID; _regExValidator.Display = ValidatorDisplay.None; _regExValidator.ControlToValidate = _textBox.ID; if(MaxLength > 0) { _textBox.MaxLength = MaxLength; } _lengthValidator.Visible = (MaxLength > 0 || MinLength > 0); _regExValidator.Visible = RegularExpression.Length > 0; _reqValidator.ErrorMessage = DisplayName + ” “ + REQUIRED; if(MinLength == 0 && MaxLength > 0) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“is too long. {0} characters max.”, MaxLength); } else if(MinLength > 0 && MaxLength == 0) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“is too short. {0} characters min.”, MinLength); } else if(MinLength > 0 && MaxLength > 0) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“has to be {0} to {1} characters long.”, MinLength, MaxLength); } else if(MinLength > 0 && MaxLength > 0 && MinLength == MaxLength) { _lengthValidator.ErrorMessage = DisplayName + ” “ + string.Format(“has to be {0} characters long.”, MinLength); } _regExValidator.ErrorMessage = DisplayName + ” “ + REGEX; } } }
FormsAuthentication.SetAuthCookie does not work the same way in ASP.NET 2.0
No commentsObviously I missed the boat somewhere along the line. I realized today that I’ve never used FormsAuthentication in an ASP.NET v2.0 application before. As it turns out, it doesn’t work the same as it used to.
C# vs Ruby Smackdown!
Finally I get to write a “smackdown” post. I had this post written for a while now, but just never got to publish it.
Here is my completely non-scientific comparison of C# and Ruby. I will come up with a simple task and will attempt to implement it in both languages. The results will be shown, but no analysis will be available; I don’t want to pick sides because I really like both languages and want to stay on good terms with both of them.
Enough of disclaimers, here is the task. Create a Day class and populate a collection of instances of class Day to represent a week. Display the week in the original order, reverse the order of the days, display the new order, restore the original order, show only the work day and show only the weekends.
Here is the expected output:
Regular Order
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
Reversed Order
Sunday, Saturday, Friday, Thursday, Wednesday, Tuesday, Monday
Regular Order
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
Work Week
Monday, Tuesday, Wednesday, Thursday, Friday
Weekend
Saturday, Sunday
Here is how I did it in C#:
1: using System;
2: using System.Collections;
3: using System.Collections.Generic;
4:
5: namespace RubyCsExample
6: {
7: internal class Example
8: {
9: public static void Main()
10: {
11: List<Day> daysOfWeek = Day.CreateWeek();
12: DisplayDays(daysOfWeek, “Regular Order”);
13:
14: //Reverse the order of the days
15: daysOfWeek.Sort(delegate(Day one, Day two)
16: {
17: return
18: (Comparer.Default.Compare(one.Ordinal,
19: two.Ordinal)*-1);
20: });
21: DisplayDays(daysOfWeek, “Reversed Order”);
22:
23: //Restore the order
24: daysOfWeek.Sort();
25: DisplayDays(daysOfWeek, “Regular Order”);
26:
27: //Show work week
28: DisplayDays(daysOfWeek.FindAll(delegate(Day d)
29: {
30: return !d.IsWeekend;
31: }), “Work Week”);
32:
33: //Show weekends
34: DisplayDays(daysOfWeek.FindAll(delegate(Day d)
35: {
36: return d.IsWeekend;
37: }), “Weekend”);
38:
39:
40: Console.ReadKey();
41: }
42:
43: public static void DisplayDays(List<Day> days, string message)
44: {
45: if (!string.IsNullOrEmpty(message))
46: {
47: Console.WriteLine(message);
48: }
49: List<string> names = days.ConvertAll(new Converter<Day, string>(delegate(Day d)
50: {
51: return d.Name;
52: }));
53: Console.WriteLine(string.Join(“, “, names.ToArray()) + “nn”);
54: }
55: }
56:
57: internal class Day : IComparable<Day>, IComparable
58: {
59: private string name;
60: private int ordinal;
61: private bool isWeekend;
62:
63: public Day(string name, int ordinal, bool isWeekend)
64: {
65: this.name = name;
66: this.ordinal = ordinal;
67: this.isWeekend = isWeekend;
68: }
69:
70: public string Name
71: {
72: get { return name; }
73: set { name = value; }
74: }
75:
76: public int Ordinal
77: {
78: get { return ordinal; }
79: set { ordinal = value; }
80: }
81:
82: public bool IsWeekend
83: {
84: get { return isWeekend; }
85: set { isWeekend = value; }
86: }
87:
88: public static List<Day> CreateWeek()
89: {
90: List<Day> days = new List<Day>(7);
91:
92: days.Add(new Day(“Monday”, 1, false));
93: days.Add(new Day(“Tuesday”, 2, false));
94: days.Add(new Day(“Wednesday”, 3, false));
95: days.Add(new Day(“Thursday”, 4, false));
96: days.Add(new Day(“Friday”, 5, false));
97: days.Add(new Day(“Saturday”, 6, true));
98: days.Add(new Day(“Sunday”, 7, true));
99:
100: return days;
101: }
102:
103: public int CompareTo(Day other)
104: {
105: return Comparer.Default.Compare(Ordinal, other.Ordinal);
106: }
107:
108: public int CompareTo(object obj)
109: {
110: return Comparer.Default.Compare(Ordinal, ((Day) obj).Ordinal);
111: }
112: }
113: }
As you can see, it took me 113 lines to achieve the required result. I am using Generics and some fancy stuff from List<>. You will need C# 2.0 to achieve similar results.
And here is the Ruby way of doing things:
1: class Day
2: attr_accessor :name, :ordinal, :is_weekend
3:
4: def initialize(name = :NotSet, ordinal = -1, is_weekend = false)
5: self.name, self.ordinal, self.is_weekend = name, ordinal, is_weekend
6: end
7:
8: def to_s
9: name
10: end
11:
12: def <=>(other_day)
13: self.ordinal <=> other_day.ordinal
14: end
15:
16: def Day.create_week
17: days = Array.new
18:
19: days << Day.new(:Monday, 1, false)
20: days << Day.new(:Tuesday, 2, false)
21: days << Day.new(:Wednesday, 3, false)
22: days << Day.new(:Thursday, 4, false)
23: days << Day.new(:Friday, 5, false)
24: days << Day.new(:Saturday, 6, true)
25: days << Day.new(:Sunday, 7, true)
26:
27: return days
28: end
29:
30: end
31:
32: def self.display_days(days, message = nil)
33: puts “#{message}n” if message
34: puts days.map{|day| day.name}.join(‘, ‘)
35: puts “nn”
36: end
37:
38: days_of_week = Day.create_week
39:
40: display_days(days_of_week, ‘Regular Order’)
41:
42: #Reverse the order of the days
43: days_of_week.sort!{ |a, b| (a <=> b) * -1 }
44:
45: display_days(days_of_week, ‘Reversed Order’)
46:
47: #Restore the order
48: days_of_week.sort!
49:
50: display_days(days_of_week, ‘Regular Order’)
51:
52: #Show work week
53: display_days(days_of_week.find_all{|day| !day.is_weekend}, ‘Work Week’)
54:
55: #Show weekends
56: display_days(days_of_week.find_all{|day| day.is_weekend}, ‘Weekend’)
As you can Ruby implementation took only 56 lines to achieve the required result.
Conclusion? I had a lot of fun playing with both languages. Give both languages a try!
12 comments