October 23, 2006

New Blog

Hi everyone. I want to let you know that I have moved to a different location. My new blog can now be found here. I had imported all the posts and comments to the new website so nothing will be lost. Please update your favorites and your rss feeds.

Thank you and as always... Happy Programming!

08:37 AM | Permalink | Comments (0)

October 18, 2006

Maintaining Collection Property State for Web Custom Controls

My blog has moved. Please go to: http://jstawski.com/archive/2006/10/18/Maintaining-Collection-Property-State-for-Web-Custom-Controls.aspx

I have dealt with this issue twice already, once being yesterday, and both times I found it very hard to find the solution. Therefore, i'm posting about it, not only for people to find the solution to their problem, but also for a reminder for me.

Anyway, developing Web Custom Controls is cool. It saves you time by using code reusability and the best part is Visual Studio makes it very easy to create one. Whenever you have properties on a control, by default they are shown on the property window of the control and whenever you set a property for the first time it adds an attribute to the tag element of that control. For example, if you set the visible property of a textbox to false at design time and then switch to the source, the textbox tag now looks like this:
<asp
:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
(note the Visible attribute.) This is the way Visual Studio implements state for design time properties. The good news is you don't have to do anything special on your control for that to work. The not so good news is that this works for primitive types like Strings, Integer, Booleans or even Enums, but not so well with collections. In order for this to work, you have to set an attributes at the property level of the control:
PersistenceMode(PersistenceMode.InnerProperty)

Happy Programming!

02:54 PM | Permalink | Comments (0)

October 05, 2006

More Control Over GridView Column

My blog has moved. Please go to: http://jstawski.com/archive/2006/10/05/More-Control-Over-GridView-Column.aspx

In response to the many comments/questions regarding the post on GridView, HyperLinkField, and JavaScript: what the #%$@! I decided to extend it and show how you can have total control over a column with the GridView.

Whenever you need to do something that is not out of the box with the GridView, like adding RadioButtons, Adding JavaScript, etc you can use the <asp:TemplateField> In there you have total control as far as what you want to insert on that column. Following the issue with the JavaScript from my other post there is an example on how to do achieve the same results:
<asp:TemplateField>
  <ItemTemplate>
    <%#"<a href=""javascript:MM_openBrWindow('../images/elevations/" & Eval("Column1") & "','img" & Eval("Column2") & "','');"">" & Eval("Column1") & "</a>"%>
  </ItemTemplate>
</asp:TemplateField>

02:19 PM | Permalink | Comments (6)

October 04, 2006

ExecuteNonQuery Always Returns -1

My blog has moved. Please go to: http://jstawski.com/archive/2006/10/04/ExecuteNonQuery-Always-Returns-_2D00_1.aspx

Whenever you want to execute a sql statement that shouldn't return a value or a record set the ExecuteNonQuery should be used. So if you want to run an update, delete, or insert statement, you should use the ExecuteNonQuery. ExecuteNonQuery returns the number of rows affected by the statement. This sounds very nice, but whenever you use the SQL Server 2005 IDE or Visual Studio to create a Stored Procedure it adds a small line that ruins everything. That line is: SET NOCOUNT ON; This line turns on the NOCOUNT feature of SQL Server, which "Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results" and therefore it makes the SP always to return -1 when called from the application (in my case a web app).

In conclusion, remove that line from your SP and you will now get a value indicating the number of rows affected by the statement.

Happy Programming!

11:55 AM | Permalink | Comments (41)

September 12, 2006

Wow, Check it out!

My blog has moved. Please go to: http://jstawski.com/archive/2006/09/12/Wow_2C00_-Check-it-out_2100_.aspx

Do you remember my previous post: Is Programming Going Away? Well today I was directed to a post that totally shocked me, but saw it coming. Pete Wright, a programmer/author that has been writing books/code since VB 3 has totaly dropped Microsoft technologies. Anyway, read his post here.

I do not agree with him 100%, but I will say I do agree 90%. The other 10%? I think he is blaming Microsoft for everything, when i think part of the blame has to be on the industry in general.

Happy programming!!

03:43 PM | Permalink | Comments (0)

September 08, 2006

Nullable Types ?!?!?!?!?!??!?!?!

My blog has moved. Please go to: http://jstawski.com/archive/2006/09/08/Nullable-Types-_3F0021003F0021003F0021003F0021003F0021003F003F0021003F0021003F002100_.aspx

Today I learned something new. Today I learned this new feature of .net 2.0 and that feature is Nullable Types. What are they? Basically they are a typed object of a primitive/value type that can hold a value or null/nothing.

What's the difference between those types and the primitive ones? The only difference from a usefullness perspective is that you can have primitive values with null rather than a predefined value. Do I think they are usefull? nope, I don't. Do I think they are going to continue on till death do us apart? No, I don't.

What's the difference of setting an integer to a predifined "null" value like -1 rather than null? None, whatsover. The only time I see when it will be usefull is if the integer type can be any of the values from integer.min to integer.max. In that case there is no real value to set as a predefined "null". Is that scenario possible? Yes, it is. Is that scenario a normal ocurrence? Not in my experience.

This thing gets more interesting. What is a boolean? A boolean is a primitive type that can only hold 2 values: True or False. So what is a Nullable Boolean? In simple terms: an oxymoron. If by definition a boolean can have 2 values: true or false, so how can a boolean be null? It can't, because if it is null then it's not a boolean. So what is the conclusion to this? Microsoft used the wrong term for the booleans. Did you ever wonder why SQL Server (just to mention one DB) doesn't have a boolean type? What, MSSQL doesn't have a boolean type?!?!?!?!??!!?!? Nope, it doesn't. It has types that can represent a boolean, but they are not booleans. What are those types? Well any type that can hold at least 2 values: int, bit, varchar(1), char(1), etc, etc. The one that resembles more to the boolean is the bit with 2 possible values: 0, 1; but as any other field in the db, it can contain nulls and therefore it makes it 3 possible values.

Will I ever use this nullable types? probably not, but the nullable int might come in handy.

Too much talk, too little code, so here's how to use nullable types in C# and VB.net:

int? x = null;
bool? flag = null; //Oxymoron :)
//Or
System.Nullable<int> x = null;
System.Nullable<bool> flag = null;

Dim X as Nullable(Of Integer)
Dim flag as Nullable(Of Boolean)

As always, happy programming!!

07:06 PM | Permalink | Comments (5)

August 29, 2006

Don't Miss Out!

My blog has moved. Please go to: http://jstawski.com/archive/2006/08/29/Don_2700_t-Miss-Out_2100_.aspx

Jonathan Goodyear, aka the Angrycoder, is presenting for Space Coast .Net User Group on Wednesday, September 20, 2006. His session is titled: "I Didn't Know You Could Do That With MasterPages."

10:52 AM | Permalink | Comments (0)

August 26, 2006

Presentation Download

My blog has moved. Please go to: http://jstawski.com/

To download the code and the presentation for my sessions at Jacksonville Code Camp, click here

03:41 PM | Permalink | Comments (0)

August 24, 2006

Jacksonville Code Camp

My blog has moved. Please go to: http://jstawski.com/archive/2006/08/24/Jacksonville-Code-Camp.aspx

Please join me at the Jacksonville Code Camp, where I will be giving 2 sessions: Developing N-Tier Application with C#, MSSQL 2005, and XML and A Beginners Session To Ajax

07:18 PM | Permalink | Comments (0)

August 09, 2006

Is Programming Going Away?

My blog has moved. Please go to: http://jstawski.com/archive/2006/08/09/Is-Programming-Going-Away_3F00_.aspx

I have found that I have a special interest in helping other people. Lately I have been getting more involved in the .net community by speaking at code camps, posting on the asp.net forums, and writing on my blog. I always liked to teach others and found it very rewarding to get a “thank you” or a “now I understand what’s going on” from the student, whoever that might be. This brings me to my point. I have spent a lot of time on the forums and interacted with a lot of others “programmers” (note the quotes) and I have found that a lot of times they really don’t know much about the platform they use (in my case the platform is web.) So, whose fault is it? Is Microsoft pushing “real programmers” away? How is this impacting programming?

          It started with Visual Studio 2002/2003 and then it evolved to Visual Studio 2005. Don’t get me wrong, Visual Studio is a great tool and makes work much more efficient, but one thing is efficiency and the other is doing all your work. With VS 2003 you can write a whole website with just learning how to use a tool. There is no need to know much about programming, but some basic programming is needed. Then came the 2005 era and Microsoft took the idea of efficiency to the extreme. I guess they wanted to show how fast you could build an application that they forgot we, programmers, get paid to program, and not only to know how to use a tool. If with VS 2003 you needed to know some basic of programming, with 2005 you could just go to a tool training session and have a website up and ready to deploy without a line of code (at least a basic website.)

          I remember when I was studying for my first certification for asp.net. I had decided to use a book from the source (I’m not going to mention the name of the book nor the publisher). I have to say I was very lucky I had years of experience with asp.net, because if it was for the book alone I would still be retaking the exam. The book concentrates in 2 things: how to use Visual Studio and learning asp.net. Doesn’t sound bad at all, especially if you need to pass the asp.net certification exam, but unfortunately it overlooks the fact that asp.net was built on top of an already well founded technology: html (and JavaScript). The book was something like this: you drag and drop a TextBox control and bingo, a weird looking tag <asp:textbox id=”tbText” runat=”server” /> becomes a beautiful, nice looking textbox on a web browser. Who cares how that happens and why your nice looking tag is now gone and you see something different like <input type=”text” id=”tbText” name=”tbText”>. All it matters is it works.

          Is this the programmers fault? I think not. I think this is what Microsoft has accomplished. You don’t need the basics as long as you know how to use a tool. So what is going to happen with the “real programmers”? Are they disappearing? I think not. Microsoft is not stupid at all. I bet they knew the effects of all this “everything works magically” technology was going to have on the programming community. Thanks to the “programmers” that know how to use a tool, the programmers that know what is going on behind the scenes can be considered experts and get paid like one.

          Until next time and happy Programming!

09:02 AM | Permalink | Comments (5)