ASP.NET - C# or Vb?

Soldato
Joined
18 Oct 2002
Posts
9,044
Location
London
Just curious..

I'm only starting out, i.e. I've just been trying to make a Hashtable, add some items, and print them out. I decided to use C# as everyone was harping on about it.

I did classic ASP (vbscript) before this, and found that I could use just about any case I like with that. However in the below snippet - C# needs 'New' to be in lower, 'If' to be in lower, and no 'T' in 'HashTable'.

Code:
if (Page.IsPostBack == true)
{
    Hashtable myHash = new Hashtable();
}

So that was an annoying half hour!
Does the same happen if I were using Vb? i.e. is it more 'forgiving'..
 
I believe that this is how it differentiates Classes from objects IIRC.

Code:
if (Page.IsPostBack == true)
{
    [COLOR=Red]Hashtable[/COLOR] [COLOR=Blue]myHash[/COLOR] = new [COLOR=Red]Hashtable()[/COLOR];
}

RED = Class

BLUE = Object (Instance of that class)
 
The blue is an identifier. The first red is a type. You can create a class with a lowercase name, it does not matter. However the style rules dictate class names should start with a capital.
 
Last edited:
KingAdora said:
Just curious..

I'm only starting out, i.e. I've just been trying to make a Hashtable, add some items, and print them out. I decided to use C# as everyone was harping on about it.

I did classic ASP (vbscript) before this, and found that I could use just about any case I like with that. However in the below snippet - C# needs 'New' to be in lower, 'If' to be in lower, and no 'T' in 'HashTable'.

Code:
if (Page.IsPostBack == true)
{
    Hashtable myHash = new Hashtable();
}

So that was an annoying half hour!
Does the same happen if I were using Vb? i.e. is it more 'forgiving'..

c# keywords are all lower case. why that makes your life harder I've got no idea.

type definitions begin upper case, hence the 'Hashtable'. your variables should use camel casing. so, myClass, myHashtable etc.
 
Sorry to be nitpicky, but == true is completely redundant as a piece of code, and never needs to appear anywhere in any application. You can remove it from that if statement and the code will run exactly as before :)

To answer your original question; no, VB.NET is not case sensitive (at least for keywords), although VS2005 will automatically correct miscasings.
 
Shame it doesn't seem to correct them the other way around. I got into the habbit of writing asp/vbscript with "If .. Then" - just because it seemed easier to read than "if then" and you'd be surprised how hard it is to 'forget' these 'bad' habbits... :(
I'm sure in Java you could write HashTable and it'd work... I guess I just have to be more accurate from now on..
Unless my IDE probably changed it to Hashtable after I pressed the spacebar.

I like how you don't have to use the 'Java import' if you create your own classes. Some nice touches from a first look - others might take some time to get used to ;)

I made a GridView (note cap V...) and although the paging and sortable fields functions are amazing (no more boring rise-repeat code writing for me!) - shame it uses javascript to do this, I assume there's no workaround for it?
 
Last edited:
What's wrong with using javascript for that? All it's doing is setting up and putting more structure in place, which you would have to do anyway.

So instead of:

<a href="?sort=title">blah</a>

It passes "sort" and "title" as parameters (and the object it applies to) to a bit of javascript that submits the form.

It makes a lot more sense to do it this way, as often you want to use javacript to validate whatever the user has entered. This way it's making you do it "the proper way" (ie. the way microsoft think it should be done).
 
What I mean is - something like 10% of people don't have JavaScript enabled. So it's not good in that respect - compared to the hardcoded ASP stuff I've done in the past.
 
There is a workaround, you code up your own GridView class.

I've been pondering re-writing swathes of code to cater for people who have javascript disabled, but hardly anyone bothers (try adding a smiley here from the icon list with javascript disable for example), and if people have it disabled and some functionality on a website is broken, that's their bad luck.

It's bad enough catering for 3 or 4 different types of browser (IE/Moz/Safari/Text only), without worrying about whether they have javascript enabled or not.

:)
 
Some of the .net controls are a bit pants really, GridView being one of them. Fine for small "internal" style sites to try and save some time but otherwise no good. It dosn't give you much control of final layout etc.

In work we just make up our own controls like a Sort control and a Paging control which we then use with a repeater, the repeater allows you complete control of the end HTML, + this way you can have the whole thing run from querystrings with no nasty javascript calls that can break your site for blind poeple etc.

Radio button list thingy is another really nasty one, look at the html it generates for you using either display option, it's totally pants and a waste of space. And using a <asp:DropDownList OnSelectedIndexChange (something like that) is really bad, breaks for blind readers and non-javascript peeps.

Rant rant.
 
DanF said:
Some of the .net controls are a bit pants really, GridView being one of them. Fine for small "internal" style sites to try and save some time but otherwise no good. It dosn't give you much control of final layout etc.

In work we just make up our own controls like a Sort control and a Paging control which we then use with a repeater, the repeater allows you complete control of the end HTML, + this way you can have the whole thing run from querystrings with no nasty javascript calls that can break your site for blind poeple etc.

Radio button list thingy is another really nasty one, look at the html it generates for you using either display option, it's totally pants and a waste of space. And using a <asp:DropDownList OnSelectedIndexChange (something like that) is really bad, breaks for blind readers and non-javascript peeps.

Rant rant.

Maybe you should look into CSS control adapter's then.
 
Just looking at that toolkit now... is it possible to do away with all the javascript hover stuff?
But more importantly, only show the submenu that you're on?
At the moment if you travel deep into the tree structure - it still shows the top level links first - so you have to again travel through all the structure just to get to the other links which are on your current sub-level...
 
Back
Top Bottom