Reflections on Software Development

Personal Blog of Mustafa Basgun

Archive for January 2008

Utilize Read-Only TextBoxes in FileUpload Control of ASP.NET

with 9 comments

Nowadays, I am spending most of my work time on developing a “document depot” type of web application which has a heavy usage of FileUpload control. And, it was one of the requirements that users should not be able to modify the associated textbox after browsing the document from their hard drives. I believe it is a very good user-experience practice and it avoids some possible security issues as well. After walking around between some search results, I have found the following solution by assuming that FileUpload1 is the ID of the control:

VB.NET:

C#:

As a result, users would be able to select a document only by using the Browse button.

I have tested the sample code with the latest versions of IE and Firefox, and everything seemed to be working fine with both browsers.

Written by Mustafa Basgun

January 28, 2008 at 5:00 PM

Rule The Back Button of A Browser by ASP.NET

with one comment

I recently needed to find a way to manage the back button of a browser for one of my applications at the work. I have found some forum entries and blog posts about the subject, but they were all some kind of complex solutions. All I wanted to do was just performing a single line code and redirecting to the main page when the user clicks the back button.

After spending couple of hours, here is the 4-step way that I came up with at the end.

First, assign an ID to the “body” tag in order to be able to call it in the Page_Load event:

Place a hidden HTML button control with an “onserverclick” event inside the page:

Add an “onunload” event (which will force a postback via Button1) to the “body” tag:

Finally, define the “onserverclick” event which was assigned to Button1 before:

Hope this helps!

Written by Mustafa Basgun

January 25, 2008 at 11:00 AM

How to Write Unique Functional Specifications Before Starting to Code?

with 2 comments

I have recently been asked to prepare some professional TE (technical evaluation) and TD (technical design) documents by one of my friends that I used to work together couple of years ago. He currently runs his own small IT consulting company here in Atlanta, and he was in a need of new format of these documents for a new client. He didn’t want something that is just a “copy and paste” of some other documentations that can be easily found on the internet. He was basically looking for a well written functional specifications that both his new client (which I guess not a computer savvy) and his application developer can understand what the final product will look like at the end.

Even though I wasn’t going to copy and paste anything from the net, but it wouldn’t hurt me to search about how to write a successful functional specifications for technical projects and I found this resource written by Allen Smith. If anyone would be asked to write functional specifications from scratch, it will be a good starting point.

Thanks Allen for sharing this great piece of writing!

Written by Mustafa Basgun

January 21, 2008 at 10:00 AM

Manipulating ColSpan Attribute of Footer Row in GridView

with 4 comments

There may be some cases that the Footer of a GridView is desired to be displayed as one cell, which means setting the ColumnSpan property of the Footer’s first cell to the number of columns of the GridView. As there are some other possible workarounds to accomplish this, here is my way by adding a few lines to the OnRowCreated method.

First, make sure that ShowFooter property of the GridView is set to True:

01202008_1.gif

VB.NET:

01202008_2.gif

C#:

01202008_3.gif

Written by Mustafa Basgun

January 20, 2008 at 2:00 PM

“LINQ to XML” in ASP.NET – Ajaxified XML Document Filtering

with 5 comments

Introduction

LINQ to XML is a new way to play with the XML data in .NET 3.5. It is actually an XML programming API that simplifies dealing with XML documents without any need to know about additional syntaxes such as XSLT and XPath. It is designed to be a cleaner, faster and lightweight API which at the same time has the key features from XSLT and XPath. According to MSDN, its public data model is aligned as much as possible with the W3C XML Information Set.

Sample XML Data and Its Filtering with “LINQ to XML”

For sampling purposes, I just created the following XML data and add it to my demo project:

My purpose is developing a simple ajaxified web application that has a dropdown with the country names and a literal that shows the capital city of selected country name from this dropdown. For this purpose, I created my server controls with some AJAX flavor as:

Then, I organized the Page_Load event as in the following in order to query over Countries.xml:

Pay attention to the usage of XDocument class from System.Xml.Linq namespace (which is already defined in the web.config file as default) in order to load the local Countries.xml file and the new casting and access methods (such as .Descendants and .Element that I used above).

Finally, after compilation the result on the browser should be like:

When “Belgium” is selected from the dropdown, literal will show the following with a partial rendering:

Conclusion

I generally work with SQL Server or Access in the data layers of my web applications, therefore I barely had a chance to put my hands on XSLT and XPath deeply. But, I can say that “LINQ to XML” as a data provider seems enough even powerful for me to handle many common XML programming tasks inside my code.

Download

You can download the demo project via here.

Written by Mustafa Basgun

January 13, 2008 at 10:00 AM