Goin the other direction...

Subscribe to Goin the other direction... 7 posts, 4 voices

 
Avatar joel 9 posts

G’day all from Australia. I’m a developer who is far more at home in RoR and PHP environments, however I am on a project now that requires the use of ASP.NET. So to all the switchers I’m hoping to get some information on how to do things I find easy (hello PHP/RoR) the hard (hello ASP.NET).

First up, a question on ASP.NET in general. Why must there be a form for server side operations to occur simply for text output?

Second, I’m attempting to keep a navigation section up to date and a little more tidy and would like to either do the equivalent of render partial or a php function where I pass a few variables to it and it will output code on the page (plus alter the class of the body and a couple of other things). Any thoughts?

Any ideas or directions on where to find potential solutions would be much appreciated.

Regards, Joel

http://euphemize.net

 
Avatar Brian Eng 49 posts

Sorry to hear that :)

You’re going to have a hard time wrapping your mind around ASP.NET if this is your first foray into Microsoft-land. ASP.NET is built very much around a desktop programming model (e.g. you have forms that have controls that raise events, etc). Much like Rails (I can’t believe I just said that), there is a convention that you should follow, and if you choose not to, it’s going to hurt.

The equivalent of a “partial” in ASP.NET (correct me if I’m wrong folks, it’s been a while) would be to use a Web User Control. If you’re using .NET 2.0+, there is the concept of “Master Pages” which are a lot like “layouts” in Rails.

I which I could point you to a single, definitive “getting started with ASP.NET” article or book. I suppose the ASP.NET quickstarts on MSDN are as good a place as any.

Best of luck.

 
Avatar Mike McClena... 19 posts

Joel,

Brian’s right – the direction you’re moving in sucks. :) It’s going to be hard for you to get used to all of the “help” that asp.net provides you.

For your first question, everything that asp.net does involves a form. That’s just the way it is. Of course, you typically don’t know that unless you View->Source because the form is hidden from you. The use of the form is mainly to provide you with viewstate so that the form magically remembers all of the data that was on the page without you having to repopulate it. This can be very handy but it certainly is overkill for a simple text output page like what you’ve described. As Brian said, you should definitely try to switch your brain out of “web programming” mode and into “windows forms” programming mode.

As for having something like render partial, Brian’s probably right there as well. Using a user control (.ascx file) is probably the easiest way to do it. It’s nowhere near as easy as a partial and it can be a real pain to pass variables but it will get you the separation that you’re looking for.

After speaking so badly of asp.net, I should mention some good things. The IDE is fantastic, intellisense is a beautiful thing, and run-time debugging is a breeze.

If you have any more questions, I’m sure that you could post them back here. Feel free to drop me an email at mike AT sideline.ca.

Good luck!

 
Avatar Andy Britcliffe 19 posts

Just to echo Mike’s post, as I’m still heavily in the asp.net land at work if you have any specific questions as you go along here feel free to ask.

Also if you’d like to try and use a MVC model in asp.net land it maybe worth checking out http://www.castleproject.org/monorail/index.html as it is a pretty well respected framework now and does give you that Rails feel – a little bit ;-)

 
Avatar joel 9 posts

Appologies for the delay all, and thank you for the comments. I kept checking my posts under my username and it didn’t indicate a reply (used to other forum software).

I know it’s going to be the biggest pain in the backside. The biggest problem I’m having at the moment is the creation of custom iterators. I’m not happy with the grid list, paginated lists etc that are provided – I need more subtle control (maybe I’m not doing things the MS way :\)

So, let’s say I want to create a custom iterator for output code, including using if/else/else-if statements, how would I go about that? I currently have a PagedDataSource object(?) so that I can use pagination. Now, I need something more than a simple Repeater, and that’s where I come unstuck. I need to be able to create (or not create) links based on variables within that object and some outside (eg a user). Any thoughts?

 
Avatar Mike McClena... 19 posts

Joel,

Just to preface this, almost all of my experience was with asp.net 1.1 so you might be able to approach it differently with 2.0 or some of the newer stuff coming out.

I would typically approach this in one of two ways.

The first way would be to see if I can use the existing controls to solve the problem. That is, can I warp the DataGrid, DataList or Repeater to do what I need. My preference was usually to use the Repeater but it depends on how complex the data needs to be. If I’m just dumping out some read only data then a Repeater is usually the best. If I need to edit the data then I’ll probably go with the DataGrid because it’s much more powerful. Of course, it’s also heavier and harder to control the output if you care about XHTML. With any of these controls, I’m probably going to use the onitemdatabound event to insert the logic into the page. Usually, I would build the page including the links but setting visible=”false”. Then I would change the visibility in the onitemdatabound code. This can get really annoying if you need to use a lot of logic.

The second way is to buy a control that is closer to what you need. There are a lot of 3rd party components that you can get that are a lot more powerful and flexible than what comes out of the box with the MS controls. The downside is that they’ll cost you $$ but that might be OK depending on how much time you’re going to waste trying to warp the existing controls to do your bidding. You can find a lot of controls at the control gallery on asp.net.

I don’t know if that helps much. If you’re still thinking of trying to build your own control then you’ll probably need to google for some articles on doing that.

 
Avatar joel 9 posts

I’m slowly getting used to it.

I really do not like the way it takes away the good control you have in other languages based on the concept that “it’s how we do it on the desktop”, because obviously it should always be that way even though it’s completely different. This is not like creating a desktop application where you’re not building up the components from machine code – the framework (x/html + css + js) exists for that and is customisable to the nth degree. The “one form to rule them all” thing is a perversion of the x/html elements – why is everything that should be run at the server enclosed by a client tag?!? and don’t even get me started on the use of non-web-specific terminology that is blatantly incorrect (but fine for desktop). >< >< >< >< >< ><

redmond, you get an “F” for the web. It’s any wonder IE6 was so poor after a year and you never bothered to undertake further development or view the web seriously. /rant (and with more to come)