Thursday, March 19, 2009

Internet Explorer 8 Back Ground color issue

Today I saw a really interesting issue. The issue come up with Internet Explorer 8. However my site is running with out any issues since lot of days. In my page, I has a some shifts to be selected to do some task. Each shift may have some color. I need to display all the shifts in their own colors. To do this I have a RadioButtonList in my asp.net page. I am adding the style attribute to the page from the code behind as follows,

radioButtonListItem.Attributes.Add("style", "color:white;background-color:" + alteredColor);

This will display the my radio button list similar to this,



However, this looked very ugly when viewed in Internet Explorer 8,



After doing a small research, I understood that the background color is missing. Unfortunately, I was unable to browse the google in a effective way, since the problem is some what new. However with some observation Microsoft provided a good alternative for this issue. There is a button named "Compatibility View" which is placed just beside address bar of IE 8,



In the above image, you can see that there is a button just beside the Address bar. While clicking this button the page will reload. This has fixed the problem in my case.

Friday, March 6, 2009

Pull the html from a different page

I will demo a small interesting feature of ASP.NET which is unknown to many people. One of the hardest things in asp.net is to build a html strings in order to send a mail. Hardest - in the sense I mean to construct a good html. However a lot of developers will try to construct all the html by making use of StringBuilder objects. Sadly many people I saw were using the strings which leave the Garbage Collector to have work more.

Well. What if you have want to format your email text is a really good manner. Or what if you want to mail the page that is already existing. However you need to get all the html from a different page. A browser can get the html generated by your ASP.NET application and IIS. While a browser can get the html why cannot your application get the html of a page. Yes, you can get the html page of your aspx page.



This feature is provided in ASP.NET by the System.Net namespace. You can create an instance of the WebClient class.



using System.Net;

.....

.....

//The parameter url is to be the full url of your web page. It cannot be physical path. For eg., Http://www.google.com/test.aspx instead of ~/test.aspx

public string getTheHtmlOutput(string url)

{

string myHtmlOutput=string.Empty;

WebClient HtmlClient=new WebClient();



//Executes the page(url) that is passed and retrieves the html in the byte array.

byte[] outputBytes=HtmlClient.DownloadData(url);

myHtmlOutput=Encoding.Default.GetString(outputBytes);

return myHtmlOutput;

}



This method will return the html of some other page in your application. However, there are even some issue behind this such as execution time. And what if there is an error in the different page. Should the error will be mailed if you are using the page for mailing purposes. However, the raising errors in this way is very rare case.

Wednesday, March 4, 2009

GridView Series

I am very happy to create my first blog. I have chosen to cover the topics on gridview. I will cover the gridview control of asp.net in a series of blogs. First of all, to say GridView is a simple table in the html point of view. This is a new control released in .NET 2.0. It offers a lot of inbuilt options such as sorting, editing, paging with out a single line of code. Of course, the sentence "Single line of code" has many restrictions. I will discuss those in my future article.

However, coming to the point the GridView is frequently used to display the data in a tabular context. This consists of lot of formatting options, which can be easily handled by the developer without any knowledge on css.

The GridView will offer us a lot of ways to bind the data to it. We can connect to the gridview via,

-The ADO.NET objects such as DataTable, DataSet, DataView
-The User Objects such as the collections, ArrayLists etc.
-The Data Source controls such as SqlDataSource, ObjectDataSource.

In the next article I will conver how to fill the data to the grid.