Posts Tagged ‘ASP.NET’
My opinion on webforms and such
Posted by fr3dr1k | Filed under ASP.NET
Today someone asked me what my opinion on webforms are or were, and sometimes I feel like the proverbial deer that gets caught with the light in his eyes. It probably seemed like I knew nothing about web forms, which is not entirely true. I mean I did a lot of my first ASP.NET programming with web forms, and its a really great platform for several reasons. Firstly you can develop a working demo of something in really short order, you don’t have to really go out and code a user control from scratch, because the controls that are already there are pretty good. I mean the Gridview/Datagrid control is pretty cool and it is pretty customizable. Secondly ASP.NET does a good job of taking HTTP from the stateless protocol it is, to a model that maintains state quite well. I coded a lot with ASP.NET Webforms and its not a bad technology or platform to work with.
In the same breath, however, I have been working with SOAP calls and web services for the last 8 to 9 months and what I like the most about this approach is the freedom to totally control the markup that is rendered in the browser. With web forms you had to deal with something called ViewState which could in some scenarios make a mess of your code. I like clean HTML. What the SOAP/Webservice model also kinda reinforces is that HTTP is stateless and should be treated as such.
I have also been doing some ASP.NET MVC and I personally like it, a lot, and will continue developing a bit more with it. There is a clean and clear separation between your presentation logic and your business logic and there is no viewstate.
Maybe I need to do some more webforms for a bit to get to grips with it again, maybe not. I do prefer spending time learning C# language features actually.
On that Session-less shopping cart issue
Posted by fr3dr1k | Filed under ASP.NET, Web Development, Web Technologies
In my post yesterday I mentioned that I would like to develop a session-less shopping cart through the use of web services and classes. Well, I changed my mind a bit because I am not sure if AJAX can maintain state. Can it? How will AJAX retain state? I’m not sure yet, so sessions it is.
There are some important reading bits that need to be covered before you can get stuck into sessions, and its always better to try and understand something as far as possible before you simply jump in and implement it. The first article that proves invaluable (and very important) is the ASP.NET Page Lifecycle where after I can recommend you read the State Management Overview Article to understand the difference between Client side and Server side state management and what each offers. Why is state management such an issue? Well firstly because HTTP is stateless, after you make a request to a web server for a web page there is no further communication between you and that server. So to create a state, you use a state management technique, which can either be client or server side. With either technique you have several options and each option has some advantages and disadvantages.
My fear with session state management was the performance hit my server might take, but I have not really tested it enough to make that assertion.
Unobtrusive JavaScript and a Session-less shopping cart
Posted by fr3dr1k | Filed under AJAX, ASP.NET
What is the idea behind unobtrusive JavaScript? What makes JavaScript unobtrusive? Does it mean removing any onlclick events in your markup and handling those click events with an approach as provided with jQuery? With jQuery its very (extremely) easy to traverse between DOM elements and its even easier associating events to elements and executing them.
I havent been doing a lot of JavaScript recently but you cannot really avoid it, but you can also not build an entire website with JavaScript and HTTPRequests alone (not search engine friendly), but you can also not rely entirely on server side code to do all the magic for you.
The other issue that has been bugging me of late is the idea of creating a session-less shopping basket, a shopping basket that uses a combination of web services and traditional classes. Within the .NET environment the only reason you might need to use sessions is to store DataTables or DataSets, but the question is how expensive is that on server resources. Would I be able to create the same session-based application with web services and traditional classes? After all you are adding web references to your web applications, and those web references all contain class declarations.
ASP.NET, handlers and IHTTPHandler
Posted by fr3dr1k | Filed under ASP.NET, C#
I have never used handlers (.ashx) files in any of my .NET web development projects, but this all changed in the last two days. The way I understand a handler is that it acts as a ‘process’ handler and does not write any output to the browser. Where would you use this? Well I used it for a shopping cart (but in hindsight I will change this) by using a handler to process the items added to the cart. The handler took a querystring and created a datatable of none existed or added the data to a datatable if that datatable already existed and stored the datatable in a session variable, which could then be accessed throughout the application. Accessing querystring variables in a handler file requires that you implement the IHTTPHandler interface, i.e. you cannot simply type Request.Querystring in the handler.
Panel and its DefaultButton property
Posted by fr3dr1k | Filed under ASP.NET, C#
ASP.NET has a server control called a panel, which allows you to display other server controls or HTML elements inside it, and one of its properties is DefaultButton. By setting the DefaultButton to the ID of a button within the panel you basically set its default keyboard event that will fire the click event associated with that button. The other alternative to this would be to add the property to the TextBox in your CodeBehind.
So, is everything event driven?
Posted by fr3dr1k | Filed under ASP.NET, Silverlight
I am busy with a Silverlight video player at the moment, and what is interesting to note and understand is that Silverlight is heavily event-driven, as is ASP.NET and a lot of the .NET framework. You can attach event handlers to almost any object, from mouse event handlers to click event handlers.
Having asked that question I took a look at the ASP.NET page life cycle and just realised how intrinsic events are in the .NET framework. There are eight basic stages in the ASP.NET page lifecycle:
- Page Request
- Start
- Page Initialization
- Load
- Validation
- Postback Event Handling
- Rendering
- Unload
Within the page lifecycle there are events raised, which allows you to write code that initialises controls that are dynamically created.
Nobody seems to know about Silverlight, for now
Posted by fr3dr1k | Filed under ASP.NET, C#, Silverlight
I would be the first to admit that not a lot of people have heard or know about Silverlight, which is Microsoft’s rich internet plugin, which is an alternative to Adobe’s Flash. It is true that Flash has been around for a long time and that Silverlight will not dislodge Flash’s entrenched following and use. But maybe, just maybe Silverlight was not designed for that purpose and that if people respond to Silverlight in certain ways it means they are taking some notice at least. The response clearly does not take into account the opportunities Silverlight offers a .NET developer. As a .NET developer I can use my C# skills to develop rich internet applications. I do not have to learn Action Script. Those same skills that I use to develop Silverlight applications can be used to develop WPF applications, ASP.NET applications and Windows applications.
Demystifying some .NET Issues
Posted by fr3dr1k | Filed under AJAX, ASP.NET, Web Technologies
What seemed a little odd to me today was that SQL Server Express 2005 is download-able from two places. Both shows different file sizes.
Another issues that needs clarity is ASP.NET and .NET framework versions. .NET 3.5 is an ‘extension’ of .NET 2.0 and replaces .NET 3.0. .NET 3.5 covers AJAX (Asynchronous JavaScript and XML) and LINQ (Language Integrated Query)
jQuery and Microsoft
Posted by fr3dr1k | Filed under AJAX, ASP.NET, Web 2.0, Web Development
I susbscribe to The Code Project’s newsletter and today I got some great news, jQuery will be supported in Visual Studio 2008. Now this is some awesome news. Makes one wonder if the Microsoft AJAX library will become redundant.
You can read the full article on Scott Gu’s website.
Re-usable code for a Gridview and DropdownList
Posted by fr3dr1k | Filed under ASP.NET, C#, Web Development, Web Technologies
Both the GridView and DropdownList server controls provided in ASP.NET have DataSource and DataBind methods. This means that you could write the same code to populate both controls with data from a database. So first you would create a method for a class like this:
public DataTable GetData()
{
string strSQL = "select * from tblTest";
using(SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDB"].ToString()))
{
using(SqlCommand myCmd = new SqlCommand(strSQL, myConn))
{
myConn.Open();
using(SqlDataReader myReader = myCmd.ExecuteReader())
{
DataTable myTable = new DataTable();
myTable.Load(myTable);
myConn.Close();
return myTable;
}
}
}
}
And then in the codebehind for the page that contains the GridView or DropDownList controls you create a new instance of the class you created above and set the DataSource property for the control. So if you created a class called myClass your code for the Gridview would look like this:
myTestClass myClass = new myTestClass();
gvMyGrid.DataSource = myClass.GetData();
gvMyGrid.DataBind();
The only difference for the DropDownList would be setting the DataTextField and the DataValueField.
