ASP.NET Charting Controls

Finally it’s nice to hear Microsoft released chart controls. They can be used with ASP.NET 3.5 by inserting <asp:chart runat=”server” /> tag in your code. What is the big difference compared to other charting tools? - it’s absolutely free.

You can download the controls, the samples and the documentation

Brief description and some screen shots can be seen on ScottGu’s blog.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

Request.Form - get values for fields having the same name

Problem
You know it’s possible to have controls with the same name on one page. In this case Request.Form[”txtSomeText”] returns the values form all 5 textboxes comma separted. (For example: text1,text2, text3.text4, text5).

Example:

.....

<input type="text" name="txtSomeText" />
<input type="text" name="txtSomeText" />
<input type="text" name="txtSomeText" />
<input type="text" name="txtSomeText" />
<input type="text" name="txtSomeText" />

.......

The question iin this case is “How to get the values for each textbox?”.
You can say “I’ll split the values…” but it’s not a good solution. What if one of the values is “text,text,text”?

I spent a lot of time splitting strings and searching for workaround of “comma values” (a,b,c) until I found the solution. Here it is..

Solution:
It’s simple: Request.Form returns NameValueCollection. GetValues is a NameValueCollection class method which gives us the requested result.

Request.Form.GetValues(”txtSomeText”) returns a string array with all the values.

, , , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

Operator ===

Have you ever used the strict equal operator? I learned about it few days ago…
Below is a quick explanation of its behavior:

“The strict equal to operator returns true if both operands are equal (and of the same type). It doesn’t perform any data type conversion, so an expression like 1 === true returns false and 1 === “1″ also returns false, because this operator checks for the type of the operands. 1 is a numerical value and “1″ is a string value; their types are different.”

Find more about Javascript comparison operators.

,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

Hide div and the white space it occupies

Problem
Most of the developers will say “I can use javascript and CSS ‘visibility’ property to do that”, but shortly after that they’ll realize that this is not enough. This solution will hide the div tag content, but the space it occupies will stay.

You can reproduce this behavior using the code below:

if (objDiv.style.visibility == 'visible' ||
   objDiv.style.visibility == '')
{
  objDiv.style.visibility = 'hidden';
}
else
{
  objDiv.style.visibility = 'visible';
}

where objDiv is the div object which you’re trying to hide.

Solution

It’s simple - initialize “display” property in addition. So the above code will look like:

if (objDiv.style.visibility == 'visible' ||
    objDiv.style.visibility == '')
{
  objDiv.style.visibility = 'hidden';
  objDiv.style.display = 'none';
}
else
{
  objDiv.style.visibility = 'visible';
  objDiv.style.display = 'block';
}
, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

ASP.NET Chart Tools

Recently I needed a flexible chart tool in order to create complicated Gantt chart with 2 layers containing timelines, one layer containing milestones and some links for the Y axis labels. After some research I came across two tools - one generating Flash charts and one generating image charts. Below I’ll describe shortly my experience with both of them.

Chart Director
This tool generates image charts of different types. You can view the image gallery and find the proper one for you. There are examples for each chart. Also it’s easy to get used to the API. The thing I like most is the support forum. There I found the solutions to all the problems I had.

Download
Purchase

Fusion Charts Instrumentation Suite
This tool generates very good Flash charts. You can preview the charts gallery. It’s easy to use and customize the charts. My problem there was that there was not support for ALT text for milestones which was important functionality I needed to implement. But in spite of this I like it very much. The support team told that this functionality will be included in the new version of the tool.

Download
Purchase

Of course there are other chart tools out there but I experiment with those two ones only.

Feel free to share your experience with those and other chart components/tools in a comment.

,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

Validators inside Update Panel don’t work properly

I’m using ASP.NET AJAX in the last project I work on and I’m very happy such control as Update Panel exists. Unfortunately today I experienced problem with validators inside Update Panel.

Problem
I have a form with some fields and validators. The validators are hidden by default.When the button is clicked the error messages appear above the form. I’m using validation summary to achieve this behaviour. When you submit the form for the first time everything’s working fine. But if you try to submit second time the validators’ error messages do not appear. Nothing is submitted to the server (so this means that the validator are working) but the error messages do not appear.

Solution
I tried to fix this on my own but without any success. Searching ASP.NET forums helped me to find the solution.

You can read a discussion explaining similar problem or the solution.

You can leave me a comment if this works for you.

, ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

Cookie is lost when browser is closed

Today I had to develop very simple and standard functionality with cookies. I’ll describe this shortly.

Task
When user visits a site for the first time a disclaimer page must be displayed. Once the user agree with it a cookie value is changed to “true” and the next time the user opens the site the disclaimer is not displayed.

Problem
The cookie is lost when the browser is closed if you change cookie value.

Research
Below is some example code that I used to investigate the problem:

  1. Open Visual Studio
  2. Create new web site
  3. Copy and paste the following code to the Page_Load method of defaut.aspx.cs file:
    if (Request.Cookies["test"] == null)
    {
      HttpCookie cookieDisclaimer = new HttpCookie("test", "cookie test");
      cookieDisclaimer.Expires = DateTime.MaxValue; // the cookie never expires
      Response.Cookies.Add(cookieDisclaimer);
    
      Response.Write("cookie added");
    }
    else
    {
      // NOTE: We'll add some lines here later
      Response.Write(Request.Cookies["test"].Value);
    }
    
  4. Buld the website and open in a browser
  5. The first time the browser opens the cookie is created. Click F5 several times and you’ll see cookie value displayed.
  6. Close the browser, open it again and navigate to the website URL. You’ll see directly the the cookie value which means that the cookie exists.

Now let’s update the code, so cookie value is changed.
Add the following code below “NOTE: We’ll add some lines here later”:

Response.Cookies["test"].Value = "cookie test";

Execute the steps described above and you’ll see that every time you open a browser the cookie is created. So the cookie expires when the browser is closed.

According to me this is not the correct cookie behaviour. Correct me if I’m wrong

Solution
The solution is simple: everytime you change the cookie value, you need to set cookie expiration date too.

So adding the following code after “NOTE: We’ll add some lines here later” fix the problem:

Response.Cookies["test"].Value = "cookie test";
Response.Cookies["test"].Expires = DateTime.MaxValue;

I hope the solution above is useful.

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

Gaia Ajax Widgets

Gaia Ajax Widgets is another framework (except ASP.NET AJAX extensions framework) built on top of the native ASP.NET server controls.

Pros:

  • Easy to use
  • Easy to extend
  • Lightweighted
  • No JavaScript required - you don’t have to write JavaScript at all
  • Gaia is FREE

Samples
Download

,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

How To Define Mozilla Specific CSS

Today I found a great approach for defining Mozilla specific styles without using Mozilla CSS extentions. The only thing needed is to put all Mozilla specific CSS definitions in a “@-moz-document” block and specify the url, url-prefix or domain to which pages the styles have to be applied:

@-moz-document url(http://www.w3.org/),
               url-prefix(http://www.w3.org/Style/),
               domain(mozilla.org)
{
  /* CSS rules here apply to:
     + The page "http://www.w3.org/".
     + Any page whose URL begins with "http://www.w3.org/Style/"
     + Any page whose URL's host is "mozilla.org" or ends with
       ".mozilla.org"
   */

  body { ... }
}

Browser compatibility
Available since Mozilla 1.8 / Firefox 1.5.

You can read more about this on Mozilla developer center website.

Now go and learn more about Mozilla CSS extentions.

,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

ASP.NET 2.0 AJAX Extensions 1.0 Released

ASP.NET 2.0 AJAX Extensions 1.0 framework was released some days ago. You can use it for developing and running AJAX-style applications. Download the framework and the documentation or just read more about ASP.NET AJAX.

ASP.NET AJAX Control Toolkit was also released along with the framework. It is a shared-source community project consisting of samples and components that make it easier to work with AJAX-enabled controls and extenders. Go to preview the demo or download the toolkit.

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb



Google

Blogroll


Blogroll Me!

Enter your email address:

Delivered by FeedBurner







Academics Blogs - Blog Top Sites