Wednesday, October 30, 2013

Close ToolStripDropdown object when parent container/form is clicked

To close the ToolStripDropdown object which is part of the textbox custom control, add event handler signatures and event definition using the code below:
//add statements in the custom control constructor  
  this.Parent.Click += new EventHandler(Parent_Click);  
  this.Parent.Move += new EventHandler(Parent_Click);  

 //event body  
  private void Parent_Click(object sender, EventArgs e)  
      _dropDown.Close(); //ToolStripDropdown object  

Focus or Caret on TextBox Control gone if ToolstripDropdown is shown.

Im trying to implement a custom textbox control with auto-suggest features. Upon rendering the ToolStripDropdown object just below the textbox control, the focus seems to be lost.

I found the trick by setting the AutoClose property to false in the Textbox OnHandleCreated(EventArgs e) event. See the code below:
 _dropDown.AutoClose = false; //ToolStripDropDown object 


Friday, October 25, 2013

Include Foreign Key Columns In The Model Disabled (ADO.NET Entity Framework)

When adding database objects to your entity data model, The checkbox option labeled (Include foreign key columns in the model) might be disabled.

I later found out that the class library's target framework was .NET 3.5 Framework. While the solution and website's
target framework is .NET 4.0.

The solution was to change the target framework to .NET 4.0 then recompiled the class library. Alas! the include foreign key columns is now enabled.


Wednesday, October 23, 2013

Accessing app.config values in class library not working (C#)

In a project that we are working with involves several class libraries. And one of them involves setting/getting the connection string. We simply added an application config file with the connection string in it. However, accessing the key/value of connection string returns null.

One possible solution is to add a Settings file in the class library where you can set the connection string. And to access the connection string value, refer to the code below:
 //Settings is the Settings File.  
 //SalesConnection is the Name of the connection string  
  return new Settings().SalesConnection;  
Here's a similar post regarding Settings File:
Setting app.config in ASP.NET

AnimationExtender Animation using JSON not working (ASP.NET)

When setting animations for AnimationExtender control using JSON/Javascript, setting the AnimationTarget with the explicit control id such as panel ID does not work when rendered to browser specified by the code below:
The workaround is to get the clientID of the panel control rendered through the browser. Below is the workaround code:
   1:  //Note: this is just a fragment of the JSON animation  
   2:  //the actual animation might be a little bit specific than this.  
   3:  var animation = "AnimationTarget":"' 
   4:  + '<%= panelDescription.ClientID %>' + '","AnimationChildren"';  
   5:  //set click behavior  
   6:  animationExtender.set_OnClick(animation);

Sunday, October 20, 2013

Multiple controls with the same ID '_header' were found. FindControl requires....( Ajax)

Good day!

After integrating ajax accordion pane controls in my app,
An exception pops up as stated by the title of the post.

The culprit was that I initialized two AccordionPane objects w/o
specifying the ID's of each object.

The solution is to include ID's in each control.See example below:
AccordionPane ap1 = new AccordionPane();  
 ap1.ID = "ap1";  
 ap1.HeaderContainer.Controls.Add(new LiteralControl("Product Code"));  
 ap1.ContentContainer.Controls.Add(new LiteralControl(datarow["ID"].ToString();));  

 AccordionPane ap2 = new AccordionPane();  
 ap2.ID = "ap2";  
 ap2.HeaderContainer.Controls.Add(new LiteralControl("Product Name"));  
 ap2.ContentContainer.Controls.Add(new LiteralControl(datarow["Prod_Name"].ToString();));

Friday, October 11, 2013

.NET 4.5 Framework Features

Here's an image i got from blog.
Thanks to the guy who uploaded this image... :)


Thursday, October 10, 2013

Combobox with CheckListBox supports Multi highlighting (C#)

A control developed by: Stelios Alexandrakis which I found it cool
is a combobox with checklistbox as the dropdown item.

After fixing a few bugs, I integrate the feature of multi-highlighting
based from the previous post on customizing CheckListBox control:
CheckBoxList Multihighlight
Here's some screenshots to illustrate each of the custom controls.

Tuesday, October 8, 2013

CheckBoxList control with multi-highlighting support (C#)

If you want to customize the CheckBoxList control to support multi-highlighting (each checked item is highlighted), you can simply override the OnDrawItem() by adding Graphics statements as shown below:
Here's an image sample of the extended CheckBoxList control:
     protected override void OnDrawItem(DrawItemEventArgs e)  
       int index = e.Index;  
                if (this.GetItemCheckState(index) == CheckState.Checked)  
                     string text = this.Items[index].ToString();  
                     Graphics g = e.Graphics;  
                     Point point = this.GetItemRectangle(index).Location;  
                     point.X += estimated_point; //estimated point is a value you may set manually  
                     SolidBrush backgroundBrush;            
                     backgroundBrush = reportsBackgroundBrushSelected;  
                     //estimated point is a value you may set manually  
                     g.FillRectangle(backgroundBrush, estimated_point , e.Bounds.Y, this.Width, e.Bounds.Height);  
                     SolidBrush foregroundBrush = reportsForegroundBrushSelected;  
                     g.DrawString(text, e.Font, foregroundBrush, point);  

Tuesday, October 1, 2013

Custom Extender type/class is undefined in AjaxToolkit/ASP.NET

When running an app that includes an ajax custom extender control, a javascript alert pops up message "EXTENDER is undefined". Sample error message:
CustomExtenders.DisabledTextBehavior is undefined
where: CustomExtenders.DisabledTextBehavior is Namespace.Type

After troubleshooting for several hours, I came up with the solution:
1. Download Ajax Toolkit Stable Release for the specific .NET Framework.
 I tried versions for September release and it's not working.
2. Replace code:
CustomExtenders.DisabledTextBehavior.registerClass('CustomExtenders.DisabledTextBehavior', AjaxControlToolkit.BehaviorBase);  
CustomExtenders.DisabledTextBehavior.registerClass('CustomExtenders.DisabledTextBehavior', Sys.Extended.UI.BehaviorBase); 

Note: AjaxControlToolkit.BehaviorBase is used in previous versions of AjaxToolkit.

AjaxControlToolkit ExtenderControlBaseDesigner class requires T


The previous version of ExtenderControlBaseDesigner does not require T as parameter. However, in recent versions you might notice that the class is declared with T. Here's a sample declaration:

T means AjaxControlToolkit.ExtenderControlBase. In order for the Custom Extender Designer to work, supply the T with class that inherits the ExtenderControlBase. This sample class inherits the ExtenderControlBase:
public class CustomPanelExtender : ExtenderControlBase  
    //your code goes here....  

Show Smart Tag(Shift + Alt + F10) is disabled/greyed in ASP.NET Server Control

When adding ajax extenders to server controls using Smart Tag, you often encounter an issue such as Show Smart Tag is greyed out/disabled.

The best thing to do is to use the latest stable version of AjaxToolkit.
And then, reset the toolbox. Sometimes, you have to close the Visual Studio IDE just to make sure.

IDE Version: Visual Studio 2010 Professional
Ajax Toolkit Binary: AjaxControlToolkit.Binary.NET4 (Stable Version)