Coolest New ASP.NET 2.0 Additions
Here are the coolest features, as I see it, in ASP.Net 2.0:
Yes, ASP.Net was a huge advance in the programming world. BUT – there were several (maybe even quite a few) annoyances that really bugged most of us. This list of Top 4 Coolest Features in 2.0 address some of those items directly.
Ok, let’s start with the biggest one of the four - . For all of us that came from Classic ASP world, this is a biggie! Though I really like the new paradigm of posting back to the same page, and use that most of the time, we’ve all found instances that really needed this feature.
if you go to the quickstarts, you’ll find an example of how to handle this. then, you’ll say to yourself, “Here we go again, with the off the wall, klunky code concepts”. However, don’t worry about it - I have good news.
First off, the posting page is NOT listed in the FORM tag. That’s not really a big problem, because it’s a property in the button control – the PostBackUrl property. For example:
<asp:Button
id="button1"
Text="Submit"
onclick="whatever"
PostBackURL="NextPage.aspx"
Runat="server" />
Then, (here’s where the new coding concept comes in) according to the QuickStarts example, we should do this, in the Postback page’s Page_Load event:
Dim SearchTerm As TextBox
SearchTerm = Page.PreviousPage.FindControl("SearchTerm")
Label1.Text = SearchTerm.Text
In this example, in ‘FindControl(“SearchTerm”)’, ‘SearchTerm’ applies to the Textbox from the previous page. That’s really not to bad, BUT, you can do it the old fashioned way, without needing to learn the new syntax:
Dim sTerm as String
sTerm=request.Form ("SearchTerm")
Label1.Text =sTerm
There, now – that wasn’t too bad now, was it?
Another really cool feature is the . On the surface of the feature’s name, you might not immediately figure out what it is, but once you think about it a while, you’ll start to get it. All of us, at one time or another have gone to a page with an input form – and yes, many times, we couldn’t start typing immediately, because the cursor’s focus was not on the first textbox in the form. So, we programmers came up with a Javascript solution, which though it worked, and was built on previous Javascript knowledge, was still, a little bit klunky to actuate on the page. To find out how this was accomplished, check out this ASPNet101.com tip, from the Tips & Tricks page.
Now, with the new Focus API – it’s easier than ever! You can use this feature in any event handler (button’s click event, Page_Load event, etc), in either of the following two ways:
TextBox3.Focus() or Page.SetFocus("TextBox3")
Alternately, the Form Tag also has a DefaultFocus property, by which we can, of course, set the focus to the default control of our choice.
Now, we come to . Boy! – Was this a long time needed feature! With the new ASP.Net paradigm of posting back to the same page – we could put multiple buttons on a page, to do a multitude of different tasks. However, if we wanted validation on some of those other controls, when a particular button’s click event handler was fired, since the validation was on the other controls, it was all or nothing – any button, when clicked, would fire the validation. Now, with ‘Validation Groups‘, in each validator, we can use the ValidationGroup Property to to group certain controls together. Then, use the same property in the button, matching the validation group of the grouped controls so validation will only occur for a certain group of controls. One word - Wow!.
And lastly, the fourth feature we’re addressing in this article is a couple of . One item in particular, which will cause a decrease in coding is the ‘OnClientClick‘ property,w hich was added to buttons/controls causing a postback. You can, along with the OnClick Event, cause a Javascript function to be called at the same time, without loosing the Server postback functions in the onClick Event, with at least one noted exception. Using the ‘disable=true’ function of Javascript on a button will, as you would figure, disable the button. And – by disabling the button, the onClick event is then unabled to be called, since it follows the client side commands.
Another Client Side goodie is the ‘MaintainScrollPositionOnPostBack‘ property of the Page Directive. It does exactly what it says it does – it maintains the Scroll Position on Postback – wherever your cursor was, when you executed a postback to that page, that’s where it comes back!
Of course, there are many, many more new features in v2.0, including new controls which greatly reduce coding, but starting here was a really good place to get started with the ‘ooh-aah’ factor!




22. Oct, 2007 








No comments yet... Be the first to leave a reply!