Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Can't find other Controls from my own Control

Reply
Thread Tools

Can't find other Controls from my own Control

 
 
Benton
Guest
Posts: n/a
 
      12-04-2006
Hi there,

I'm creating a "PopUpDatePicker" control, inheriting from Hyperlink. The
goal is to click on that control, select a value from a Calendar and set
this date value to a target control, usually a TextBox.

Problem is on the OnPreRender event, where I try to find the target control.
The FindControl() method always return null there, that is, the specified
Target control is not found on the current page. Here's the event code:

protected override void OnPreRender(EventArgs e)

{

System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as
System.Web.UI.Page;

Control control = page.FindControl(TargetControl);

if (control != null) // null is always returned here

this.Attributes.Add("onclick",
string.Format("window.open('DatePicker.aspx?field= {0}', 'calendarPopup',
'width=230,height=209,resizable=no,statusbar=no'); ", control.ClientID));

base.OnPreRender(e);

}

And below is the full code-behind, too. The question is: Why is the
FindControl() method returning null here? The TargetControl property does
have the name of the target control on the page (I can see it with the VS
debugger) so that is not the problem. So what am I missing?

Thanks in advance,

-Benton

Full code-behind below:


using System;
using System.Drawing;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

[assembly: TagPrefix("Tenerife.WebControls", "Tenerife")]

namespace Tenerife.WebControls

{

[ToolboxData("<{0}opUpCalendar runat=server></{0}opUpCalendar>"),

ToolboxBitmap(typeof(Calendar))]

public class PopUpCalendar : HyperLink

{

public PopUpCalendar()

{

this.NavigateUrl = "javascript:;";

this.ImageUrl = "~/img/SmallCalendar.gif";

this.ToolTip = "Click to select date";

}

protected override void OnPreRender(EventArgs e)

{

System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as
System.Web.UI.Page;

Control control = page.FindControl(TargetControl);

if (control != null) // This is always false

this.Attributes.Add("onclick",
string.Format("window.open('DatePicker.aspx?field= {0}', 'calendarPopup',
'width=230,height=209,resizable=no,statusbar=no'); ", control.ClientID));

base.OnPreRender(e);

}

[IDReferenceProperty(typeof(Control))]

[Themeable(false)]

[TypeConverter(typeof(System.Web.UI.WebControls.Val idatedControlConverter))]

[DefaultValue("")]

public string TargetControl

{

get { return ViewState["TargetControl"] == null ? String.Empty :
ViewState["TargetControl"].ToString(); }

set { ViewState["TargetControl"] = value; }

}

}

}

 
Reply With Quote
 
 
 
 
Benton
Guest
Posts: n/a
 
      12-04-2006
> I'm creating a "PopUpDatePicker" control, inheriting from Hyperlink. The
> goal is to click on that control, select a value from a Calendar and set
> this date value to a target control, usually a TextBox.


Adding something to my own question here. I've modified my OnPreRender event
to look like this:

protected override void OnPreRender(EventArgs e)
{

Control control = Page.FindControl(TargetControl);


this.Attributes.Add("onclick",
string.Format("window.open('DatePicker.aspx?field= {0}', 'calendarPopup',
'width=230,height=209,resizable=no,statusbar=no'); ", control.ClientID));

base.OnPreRender(e);

}

This time I am not casting the current page from the current handler, I'm
just using the Page property the Hyperlink control inherited. However, the
result is just the same: FindControl() always returns null. What am I doing
wrong?

Thanks in advance,

-Benton

 
Reply With Quote
 
 
 
 
Benton
Guest
Posts: n/a
 
      12-04-2006
>> I'm creating a "PopUpDatePicker" control, inheriting from Hyperlink. The
>> goal is to click on that control, select a value from a Calendar and set
>> this date value to a target control, usually a TextBox.

>
> This time I am not casting the current page from the current handler, I'm
> just using the Page property the Hyperlink control inherited. However, the
> result is just the same: FindControl() always returns null.


Duh. Solved by using NamingContainer.FindControl() instead of
Page.FindControl(). Long live GoogleGroups.

Cheers,

-Benton



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using own classloader inside J2EE to load and unload own classes. Stefan Siegl Java 1 07-02-2013 05:05 AM
Allowing access to my own computers within my own network =?Utf-8?B?VHJldm9y?= Wireless Networking 2 07-20-2006 09:05 PM
I have built my own (simple) thread manager [TM], but just found java 5 has its own. Saverio M. Java 0 07-03-2006 08:52 AM
Your own photos in your own book Frank ess Digital Photography 1 12-09-2004 05:54 PM
Spam: Re: Own Your Own On-Line Travel Agency Howard NZ Computing 0 08-01-2003 07:46 AM



Advertisments