Recent Posts

Tags

Community

Email Notifications

All Links

Blogs I Read

My Articles

JavaScript & CSS

Date & Time

SQL Server 2000/2005

Articles I Read

ASP.NET Free Controls

MVFP (Most Valuable Forum Posts)

Archives

September 2005 - Posts

First Day @ Yukon Training

I am now sitting in the middle of a training given by Microsoft and ACT College on SQL Server 2005 (Yukon) in a very comfortable place in the Great Capital of Lebanon - Beirut.

More on the topics and issues discussed will be available online soon.

Regards

 

Define Custom Event in a Control

If you are working with either a new custom server control or a normal web user control, this is the proper way of adding an event that can be handled by the parent control of the child control you are develping:

Add the following to the control (Server Control / Web User Control ) being developed:

#region Event Handler 
private static readonly object EventBubbleRaised = new object(); 
public event EventHandler BubbleRaise 
{ 
       add 
      { 
                Events.AddHandler(EventBubbleRaised, value); 
       } 
       remove 
      { 
               Events.RemoveHandler(EventBubbleRaised, value); 
      } 
} 
protected virtual void OnBubbleClick(EventArgs e) 
{
              EventHandler BubbleRaised = (EventHandler)Events[EventBubbleRaised]; 
              if (BubbleRaised != null) 
                      BubbleRaised(this, e); 
} 
#endregion

In the parent page / control, you add this in the Init method:

BubbleControl.BubbleRaise += new EventHandler(ControlName_BubbleRaise);


Then you define you our handler:

private void ControlName_BubbleRaise(object sender, EventArgs e) 
{ 
                Response.Write(sender.GetType().ToString()); 
}

That was a simple example, but at least you know now the steps.

Regards

Dynamic Loading of UserControl in ASP.NET 2.0 Beta 2

I was trying to dynamically load a user control in an ASP.NET 2.0 project.

The problem was, the code-file could not be seen in my ASPX page.

To make this work, I did the following steps:

1- I put my usercontrol in a new normal folder called: App_UserControls,

2- Add this to the top of the ASPX page:

<%@ Register TagPrefix="uc1" TagName="TestControl" Src="App_UserControls/test.ascx" %>

<%@ Register TagPrefix="uc1" TagName="TestUC" Src="App_UserControls/test.ascx" %>

Then in my code-beside:

Control uc = this.LoadControl("~/App_UserControls/test.ascx");
((
test)uc).Name = "Bilal Haidar";
phControls.Controls.Add(uc);

Now things are ok, but ...

The main problem is, why do we need to Register the user control in a time we are dyanamically laoding the user control?

 

Regards

Posted: Sep 12 2005, 03:00 PM by simple | with 6 comment(s)
Filed under:
FindPageControl :: Get Control inside a content page

In my previous post, I talked a problem in ASP.NET 2.0 using Master Pages.

I recommend using the following:

In the BaseClass of your aspx pages in ASP.NET, add the following:

protected Control FindPageControl(string ControlName, string ContentHolderName)
{
       // Get the ContentPlaceHolder Control
      ContentPlaceHolder _CPH = 
(ContentPlaceHolder)this.Page.Controls[0].FindControl(ContentHolderName);
// Get the required control inside ContentPlaceHolder control Control _ctrl = _CPH.FindControl(ControlName); return _ctrl; }

In your aspx page, you can find the control as follows:

((CheckBoxList)this.FindPageControl("chkDays","ContentPlaceHolder1")).Items.Count

Hope that helps,

Regadrs


 

Posted: Sep 02 2005, 03:18 PM by simple | with no comments
Filed under:
FindControl while using Master Pages

There is something missing in ASP.NET 2.0 Master Pages Beta 2 in the way we access controls on the content page.

For example, I use the following lines of code to get a reference to the CheckBoxList (CheckDays) on a page placed inside the ContentPlaceHolder:

string ControlName = "ctl00$ContentPlaceHolder1$CheckDays";
CheckBoxList _chkList = (CheckBoxList)Page.FindControl(ControlName);
Shouldn't the ASP.NET 2.0 team find a solution in something like:
CheckBoxList _ckhList = this.FindControl("CheckDays") // this refers to ContentPalceHolder
 
 
Thank you,
 
Posted: Sep 02 2005, 10:37 AM by simple | with no comments
Filed under:
Inside ASP.NET 2.0 Master Pages

A great article on ASP.NET 2.0 Master Pages:

Inside ASP.NET 2.0 Master Pages

 

Regards

 

Posted: Sep 01 2005, 06:33 PM by simple | with no comments
Filed under: