locked
Rendering Repeater in Custom WebControl RRS feed

  • Question

  • User-1245426334 posted

    Hi!

    I think I'm having a simple issue, but could use some help with how to fix it.

    I'm creating a custom web control in my App_Code section (it's inheriting WebControl). In it, I have a Repeater object that is the basis of the control.

    I've overriden the Render method with this:

    protected override void Render(HtmlTextWriter writer)
    {
          /* SET SOME ATTRIBUTES FOR REPEATER */
    
          rEventPreview.RenderControl(writer);
    }

    The repeater always renders like no data is returned, but it should be returning one item.

    I know it's not the settings of the repeater (I've created the repeater with the same settings on a page and it renders correctly). So now I'm wondering if it has to do with where I'm setting the attributes. I've tried setting them by overriding the OnInit and OnDataBinding methods, but that didn't help either.

    Could someone please help me?

    Thanks!

    -Eric

    Thursday, July 5, 2012 5:01 PM

Answers

  • User-1501801757 posted

    Usually to assing the datasource it's just like the regular control

    so if your class

    public class repeat : Web.UI.Controls.Repeater (thats a guess on where it's found)

    {

    }

    is all you had done.  then all you would need to do is assign it like you normally do.

    It shouldn't require any crazy code as long as the base is the control

    the only thing you need to be doing differently is override where it shows the repeater and show a label instead.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2012 5:30 PM

All replies

  • User-1501801757 posted

    Have you put a break point there onRender to make sure something isn't causing it to fire more than once?  Also can you confirm the writer property that is being sent to it has a value in that render method also.  i'm just wondering if something isn't setting the datasource properly.  Or to late.  Override the ondatabinding and put something like string s = string.Empty. Then put a breakpoint there just to confirm that it's even binding right and only once.

    Thursday, July 5, 2012 5:15 PM
  • User-1245426334 posted

    Well the repeater is a custom control from our CMS. It allows us to specify text to display if Zero Rows are returned. The control consistantly displays that text, so I know the control is rendering. It's more that it's not rendering properly because it's not getting the data from the database.

    I've already emailed their support techs, but I was wondering if someone here had any ideas that might help.

    Since this is the first time I've created a custom control this way, I figured I was not assigning the properties at the correct time.

    Thanks!

    Thursday, July 5, 2012 5:22 PM
  • User-1501801757 posted

    Usually to assing the datasource it's just like the regular control

    so if your class

    public class repeat : Web.UI.Controls.Repeater (thats a guess on where it's found)

    {

    }

    is all you had done.  then all you would need to do is assign it like you normally do.

    It shouldn't require any crazy code as long as the base is the control

    the only thing you need to be doing differently is override where it shows the repeater and show a label instead.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2012 5:30 PM
  • User3866881 posted

    The repeater always renders like no data is returned,

    Have you save the Data contents in the ViewState or Session?You should know that without doing this,Html is of non-memorization……

    Reguards!

    Friday, July 6, 2012 10:04 PM