locked
Creating a wrapper control. RRS feed

  • Question

  • User-508353232 posted

    I have a requirement to create a wrapper control. And I am sure my requirements is something that most of people would have come across.

    My web page is going to have few user controls on it. Every user control is supposed to have a textbox on the top that will capture the title of the user control and a close button on the right which when clicked will hide the user control. Pretty much similar to a webpart. However I dont want to use 2.0 webpart for this since it does a post back for whatever it does.

    The way I want to do this is, I want to write a custom panel control called MyWrapper. When I wrap any user control within MyWrapper, what it should do is, it should create a table with first row as a row with a texbox and anything else. Second row with just one cell and all the child controls of the panel added to it.

     Once I have this custom control, then what I can do is, whichever user control needs to have this kind of layout, I can wrap it within the MyWrapper control.

    The design I have in mind is, I will create a custom control that inherits from asp panel control and in the render method i will create the table I want and put all the panel child controls within it. I tried a sample code but got few weird erros about enumerator binding.

     Has someone worked on something like this before. Can you share your designs with me or suggest me few things here?

    Thanks,

    Nilesh



     

    Thursday, June 7, 2007 7:13 PM

Answers

  • User-706614543 posted

    I have just started out with custom server controls(I have only written 3 of them), but I think what you might be looking for would actually be to create a custom control that inherits from compositeControl.  Composite controls atomatically implements IEnumerable (which I think is why you are getting the errors).  From there you can overide the createChildControls method and build out your panel and label.  Then you can create a templated region so you would have a template that you can use to populate the meat of your wrapper control with your user control or whatever you may wish.  I am not sure that this is actually the best way, but it would be the way that I would try to tackle the project.

    If there is a better way to do somthing like this I would like to here it also.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 8, 2007 9:10 AM

All replies

  • User-706614543 posted

    I have just started out with custom server controls(I have only written 3 of them), but I think what you might be looking for would actually be to create a custom control that inherits from compositeControl.  Composite controls atomatically implements IEnumerable (which I think is why you are getting the errors).  From there you can overide the createChildControls method and build out your panel and label.  Then you can create a templated region so you would have a template that you can use to populate the meat of your wrapper control with your user control or whatever you may wish.  I am not sure that this is actually the best way, but it would be the way that I would try to tackle the project.

    If there is a better way to do somthing like this I would like to here it also.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 8, 2007 9:10 AM
  • User-1757557837 posted

    I know this is an old post, but if this answered your question, is there anyway you possibly have an example you can share on how you accomplished this?  I have a similar inquiry at http://forums.asp.net/t/1458252.aspx

    Wednesday, August 12, 2009 3:57 PM