Asp.Net: Charting Control (Error ChartImg.axd)

After installing and playing with the Asp.Net Charting control I decided to use it for a customer. When integrating the control to the project I got the following error

"Error executing child request for ChartImg.axd"

This error occurred because I did not update my web.config file. You have to add the following appSettingkey, httpHandler and handler.


    <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:TempImageFilesDit;" />
    <add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />

    <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />


More info about the Charting control:

Enjoy charting,

Asp.Net: Menu control remove MenuItem (MenuItemDataBound)

For a project I needed to remove menu items to the pages in the folder ‘Subscriberpages’ when a the user is in the Role of ‘Marketing’ and ‘AccountManagement’. To do this I added the following code to the MenuItemDataBound event.

protected void mainMenu_MenuItemDataBound(object sender, MenuEventArgs e)
 SiteMapNode node = e.Item.DataItem as SiteMapNode;

 if (node.Url.Contains("<em>Subscriberpages</em>"))
  if (HttpContext.Current.User.IsInRole("<em>Marketing</em>") || HttpContext.Current.User.IsInRole("<em>AccountManagement'</em>"))
   // Get menu.
   Menu topMenu = (Menu)sender;

   // Remove dataitem from menu.

To generate the menu I used the Web.sitemap and the asp:Menu control.

Asp.Net: Using the OnCommand Event with CommandArgument

When using a button, linkbutton or imagebutton with CommandArguments or CommandName you can use the OnCommand event instead of the OnClick event. Using the OnCommand Event you use less code to extract the CommandArgument and CommandName from the Event comparing to the OnClick event (because you don’t need to cast the control).
Code example

The Aspx:

&lt;asp:ImageButton ImageUrl=&quot;~/Includes/Images/delete_icon.gif&quot; runat=&quot;server&quot; ID=&quot;ibtDeleteClip&quot; OnCommand=&quot;ibtDeleteClip_Command&quot; CommandArgument=&#039;' /&gt;

And the codebehind (C#):

protected void ibtDeleteClip_Command(object sender, CommandEventArgs e)
   string commandArg = e.CommandArgument;

Asp.Net: Databinding a array of strings

You can use a string array as datasource and view the string values by using the Container.DataItem property.

Code example



string[] testData = {"1","two","3","4"};
rptDemo.DataSource = testData;


And in the .aspx:


<asp:Repeater runat="server" ID="rptDemo">
        <%# Container.DataItem %>


Some tips for the dropdown control

I always have problems implementing the Asp.Net dropdown control. Here are some simple tips to make your life (with dropdown controls) easier.

Adding an default item with data binded dropdown

To add an default listItem to your data binded dropdown list you just have to add a ListItem on the first place (0) of your control

CountryDropdown.DataSource = countryList;
CountryDropdown.DataValueField = "CountryId";
CountryDropdown.DataTextField = "CountryName";

//Add the item
CountryDropdown.Items.Inser(0, new ListItem("== Choose a Country =="));

Getting the selected value


Setting dropdown listitem by value

dropDownList.SelectedIndex = dropDownList.Items.IndexOf(dropDownList.Items.FindByValue(option.OptionValue));

Validation on a dropdownlist

Hope it helps.

ListView: OnItemDataBound

Get dataItem onItemDataBound (don't forget to replace the bold parts with your objectname):


protected void MainPostListView_ItemDataBound(object sender, ListViewItemEventArgs e)


YourObject item = (YourObject)((ListViewDataItem)e.Item).DataItem;




Findcontrol within the itemtemplate:


HyperLink hplTitle = (HyperLink)e.Item.FindControl("hyperLink");