+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Why can't I find a control in EventsView

Why can't I find a control in EventsView

12 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Oct 2010
    Link to this post
    Hi,

    I have a control that is inheriting from EventsView. I am mapping an external template for the control.

    [DisplayName("Events view")]
    public class EventsViewControl : EventsView {
     
        public EventsViewControl() { }
     
        public override string ItemListTemplatePath {
            get { return "~/Sitefinity/ControlTemplates/Events/ContentViewItemView.ascx"; }
        }
     
        public override string SingleItemTemplatePath {
            get { return "~/Sitefinity/ControlTemplates/Events/ContentViewSingleItemView.ascx"; }
        }


    Within my external template I have a radiobuttonlist which i need to be able to get access to, but every method I try returns null. I've tried:

    protected virtual RadioButtonList oCategoryList {
            get {
                return base.FindControl("radlstCategory") as RadioButtonList;
                
            }
        }

    And then:
    this.FindControl...
    this.Control[0].FindControl - returns an error...

    Any ideas?

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Oct 2010
    Link to this post
    Hello Alastair,

    You need to use Container.GetControl<T>

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Oct 2010
    Link to this post
    Hi Ivan,

    That's what I originally thought, but neither "base" or "this" have a Container object in this instance.

    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Oct 2010
    Link to this post
    Hi Alastair,

    You an use SingleItemContainer or ItemListContainer.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Oct 2010
    Link to this post
    Ah i see, perfect, thanks.

    I can get access to the control now, but SelectedValue never has a value using:

    oCategoryList.SelectedValue

    Can there be any reason why?

    Higgsy
  6. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Oct 2010
    Link to this post
    Sorry i didnt explain that very well.

    From within the overriden methods CreateDataSource, GetFilterBuilder and CreateChildControls the selectvalue for oCategoryList is empty. If i check it from within OnLoad there is a valid value.

    However, I need to check what the value is from within CreareDataSource and GetFilterBuilder, because the Selected RadioButton ListItem is used within my filter expression.

    Is it possible perhaps to called CreateDataSource from within onLoad?

    Regards,
    higgsy
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Oct 2010
    Link to this post
    Hi Alastair,

    Create a ViewState property and set its value on load. Then get the value inside CreateDataSource()

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Oct 2010
    Link to this post
    Hi Ivan,

    Sorry im not understanding how that will work. CreateDataSource is executed before OnLoad so any value i set in the OnLoad handler will not be present at the point CreateDataSource executes....

    Am i mis-understanding your suggestion...?

    higgsy
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Oct 2010
    Link to this post
    Hello Alastair,

    CreateDataSource is called after OnLoad. CreateDataSource is called inside CreateChildControls.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Oct 2010
    Link to this post
    Hi Ivan,

    It appears onload is only executed prior to createdatasource when the control is first executed. Not if it is posted back.

    If I run the following code:

    protected override System.Collections.IList CreateDataSource() {
     
        Context.Response.Write("<br />Im executing from within CreateDataSource()");
     
     
        ContentFilterBuilder filterBuilder = this.GetFilterBuilder();
        if (filterBuilder.IsFilterValid)
            return this.Manager.GetContent(base.GetContentStartIndex(), base.GetPageSize(), base.SortExpression,
                                      filterBuilder.ParseTagFilter(), ContentStatus.Published, null,
                                      filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter());
     
        return base.CreateDataSource();
    }
     
    protected override void OnLoad(EventArgs e) {
                 
        //set viewstate properties which can be read from createdatasource
        this.ViewState["Category"] = oCategoryList.SelectedValue.ToString();
        this.ViewState["County"] = oCountyDropDown.SelectedValue.ToString();
     
        Context.Response.Write("<br />Im executing from within OnLoad()");
     
        base.OnLoad(e);
     
    }

    When i first enter the page my response.write statements print out:

    Im executing from within OnLoad()
    Im executing from within CreateDataSource()

    But then if i click the submit button, I get:

    Im executing from within CreateDataSource()
    Im executing from within OnLoad()

    At which point I'm back to square one, no-way of finding what the dropdownlist values are...

    Regards,
    higgsy

  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Oct 2010
    Link to this post
    Hello Alastair,

    First you can use RadCombobox and SelectedIndexChanged event where you get the selected value from a view state property. Inside the event you need to filter the control data by using ContentFilterBuilder and  call this.RecreateChildControls(); to update your data properly. In this case you do not have to override CreateDataSource method, because you can filter the list inside CreatechildControls before calling the base.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Oct 2010
    Link to this post
    Hi Ivan,

    Ok - i've got there. I've got round it by adding a click event to the button, and using the recreatechildcontrols method as you suggested.

    protected override ContentFilterBuilder GetFilterBuilder() {
     
        ContentFilterBuilder filterBuilder = base.GetFilterBuilder();
        MetaSearchInfo filter = new MetaSearchInfo(MetaValueTypes.ShortText, "Category", oCategoryList.SelectedValue, SearchCondition.Equal, JoinType.And);
        filterBuilder.ClearFilter();
        filterBuilder.AddFilter(filter);
     
        return filterBuilder;
    }
     
     
    protected override void CreateChildControls() {
     
        //set some properties
        this.BookmarkEnabled = false;
     
        //create controls
        base.CreateChildControls();
     
    }
     
    void oSubmitButton_Click(object sender, EventArgs e) {
     
        ContentFilterBuilder filterBuilder = this.GetFilterBuilder();
        if (filterBuilder.IsFilterValid) {
     
            this.Manager.GetContent(base.GetContentStartIndex(), base.GetPageSize(), base.SortExpression,
                                      filterBuilder.ParseTagFilter(), ContentStatus.Published, null,
                                      filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter());
     
            base.RecreateChildControls();
     
        }
     
    }
     
    protected override void OnLoad(EventArgs e) {
     
        #region Register_Events
     
        this.oSubmitButton.Click += new EventHandler(oSubmitButton_Click);
     
        #endregion
     
        base.OnLoad(e);
     
    }

    One last thing - my radiobuttonlist does not maintain its state. Is something within SiteFinity removing the state?

    Thanks for all your help
    higgsy
Register for webinar
12 posts, 0 answered