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.
Javascript files are typically registered in the PreRender phase, and this might explain the problem to some extent - maybe they never have a chance to be registered, since RenerControl is called by Render, which occurs later in the cycle.
If you are creating a composite control, I suggest moving the code to the CreateChildControls methods (you can override the base WebControl.CreateChildControls method) - this method is automatically called by the framework and is the recommended way by Microsoft for these types of scenarios.
Otherwise, you can try moving the code in other events, like OnInit or OnLoad and see if you get better results.
Please, let me know if this helps.
I should have been more clear, and I apologize for that.
The code I posted is run in the parent control constructor, and is just being rendered via RenderControl().
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); } }}
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.