I have added a WebDateChooser to a WebControl. I noticed that I had to specify the image directories in order to get the arrow to show up, something I didn't have to do when using it in a TemplatedColumn. Anyway, everything shows up as it should, but nothing happens when I click on it.
My code is as follows:
mDateChooser = new Infragistics.WebUI.WebSchedule.WebDateChooser();mDateChooser.JavaScriptFileName = "Infra/ig_webscheduleinfo.js";mDateChooser.JavaScriptFileNameCommon = "Infra/ig_shared.js";mDateChooser.ID = string.Format("mDateChooser_{0}", this.Parameter.IteratorValue);mDateChooser.Width = Unit.Percentage(100);mDateChooser.Format = Infragistics.WebUI.WebSchedule.DateFormat.Short;mDateChooser.ImageDirectory = "Images/";mDateChooser.DropButton.ImageUrl1 = "ig_cmboDownXP1.png";mDateChooser.DropButton.ImageUrl2 = "ig_cmboDownXP2.png";
I'm kind of assuming that it's the javascript file. I've tried all that seem right, and I don't know how to specify more than one. Thanks.
Cool - glad I was able to help. This was an interesting case - maybe we need to create a guide for using our controls in composite server controls, since it is really a very tricky topic.
Thanks for you help, Rumen. I have it working now.
This happens because by default WebControl renders all child controls in the Controls collection (and controls need to be added there in order to become part of the control tree).
A possible solution is to override the Render method of your parent control and not call base.Render()
This is working (sort of), but there is an issue. I don't want to render the WebDateSelector control until I call it via the controls Render() override: mDateChooser.RenderControl(writer). I am rendering these controls inside a row that is being added to a table in the parent container control. Why is it rendering when I add it to the pages child controls?
Page: GridParameters.aspx
Page_Load(){ mParamControlList = new ParamControlList(mSql); mHolder.Controls.Add(mParamControlList);}
WebControl: ParamControlList.cs
ParamControlList() constructor{ ParamControl pc = new ParamControl(param); this.Controls.Add(pc);}
Render() override:
foreach (Control c in this.Controls){ if (c.GetType() == typeof(WebDashboard.ParamControl)) c.RenderControl(writer);}
WebControl ParamControl.cs:
Constructor:
mDateChooser = new Infragistics.WebUI.WebSchedule.WebDateChooser();mDateChooser.ID = string.Format("mDateChooser_{0}", this.Parameter.IteratorValue);mDateChooser.Format = Infragistics.WebUI.WebSchedule.DateFormat.Short;
CreateChildControls() override:
this.Controls.Add(mDateChooser); <-- this renders the control. I only want it added to the page, not rendered yet.
writer.RenderBeginTag(HtmlTextWriterTag.Td);mDateChooser.RenderControl(writer); <-- This renders a non-usable WebDateChooser writer.RenderEndTag();
-------------------------------------------------------------------------------------------------------------------
Obviously I am missing something, but can't see it.
Thanks for the follow-up. On a second though, do you add the instance of the WebDateChooser to the parent Controls collection as well? This way, rendering will happen automatically the way the control expects and there will be no need to use Render/RenderContents at all.
I have just created a sample server web control and things worked for me (I am using the built-in javascript files, not external ones, but I think the same principles should apply). Another idea - are you sure that the ID you generate does not contain some characters that may create invalida identified in Javascript - I've seen problems related to that as well.
Here is my code for the server control that is working for me
[DefaultProperty("Text")] [ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")] public class CustomWebChooser : WebControl { [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? "[" + this.ID + "]" : s); } set { ViewState["Text"] = value; } } protected override void CreateChildControls() { base.CreateChildControls(); Infragistics.WebUI.WebSchedule.WebDateChooser mDateChooser = new Infragistics.WebUI.WebSchedule.WebDateChooser(); //mDateChooser.JavaScriptFileName = "Infra/ig_webscheduleinfo.js"; //mDateChooser.JavaScriptFileNameCommon = "Infra/ig_shared.js"; mDateChooser.ID = string.Format("mDateChooser_1"); mDateChooser.Width = Unit.Percentage(100); mDateChooser.Format = Infragistics.WebUI.WebSchedule.DateFormat.Short; mDateChooser.ImageDirectory = "Images/"; //mDateChooser.DropButton.ImageUrl1 = "ig_cmboDownXP1.png"; //mDateChooser.DropButton.ImageUrl2 = "ig_cmboDownXP2.png"; this.Controls.Add(mDateChooser); } }}