Composite control and resizing

Discussion in 'ASP .Net Building Controls' started by J.Marsch, Oct 9, 2003.

  1. J.Marsch

    J.Marsch Guest

    I'm a little new to Web Forms, and building web form controls:

    I am trying to build a simple composite web form control. It contains a
    Label, with a TextBox
    At design time, if the user attempts to resize the control, I want for the
    Textbox to resize along with it, so that its width matches that of the
    container, and if you change the height of the container, the height of the
    Textbox is adjusted -- basically, the text box should take up the entire
    container except for the space used by the Label.

    No matter how hard I fight it, I cannot seem to get this resize behavior to
    work right.
    What seems to be throwing me off is that it appears to be possible to have
    an empty height. How can I figure out how to set the height of the
    contained control if the label shows a height of 0? It's height obviously
    isn't zero, because I can see it when it renders. I think that there is
    either a bug, or something basic that I don't follow.



    I didn't think it should be too difficult. Here's basically what I've got:

    (leaving out some additional complexity)

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
    this.EnsureChildControls();
    this.EditControl.Width = this.Width;
    this.EditControl.Height = new Unit(this.Height.Value -
    this.FieldLabel.Height.Value);
    base.Render(writer);
    }

    protected override void CreateChildControls()
    {
    this.FieldLabel = new Label();
    this.Controls.Add(this.FieldLabel);
    this.EditControl = new TextBox();
    this.Controls.Add(this.EditControl);
     
    J.Marsch, Oct 9, 2003
    #1
    1. Advertisements

  2. Hi,

    I am checking this issue and will update you with my information.

    Have a nice day!

    Regards,

    HuangTM
    Microsoft Online Partner Support
    MCSE/MCSD

    Get Secure! -- www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Tian Min Huang, Oct 9, 2003
    #2
    1. Advertisements

  3. J.Marsch

    J.Marsch Guest

    Thanks Tian:

    I noticed that I left out one item in code that I posted to you. In the
    CreateChildControls method, I insert a literal <br> after the label, so that
    the label and the edit control appear on separate lines:

    protected override void CreateChildControls()
    {
    this.FieldLabel = new Label();
    this.Controls.Add(this.FieldLabel);

    Literal lineBreak = new Literal();
    lineBreak.Text = "<br>";
    this.Controls.Add(lineBreak);

    this.EditControl = new TextBox();
    this.Controls.Add(this.EditControl);
    }
     
    J.Marsch, Oct 9, 2003
    #3
  4. J.Marsch

    Genich Guest

    I run your code and it work fine in resizing the child controls on the
    designer the way you want it them to.
    If that don't help you, try this:
    this.EditControl.Width = Unit.Percentage(100);
    //this.Width;
    this.EditControl.Height = Unit.Percentage(100);
     
    Genich, Oct 13, 2003
    #4
  5. Jeremy,

    In order for me to reproduce the problem you are encountering, can you
    provide me with a scaled-down reproduction of what you are doing? You can
    e-mail it to me at the e-mail address on this post. Just leave off the
    "online".

    Jim Cheshire [MSFT]
    Developer Support
    ASP.NET


    This post is provided as-is with no warranties and confers no rights.

    --------------------
     
    Jim Cheshire [MSFT], Oct 13, 2003
    #5
  6. Jeremy,

    I haven't heard from you, so I'll assume you got it fixed up. If you still
    need my help, post back!

    Jim Cheshire [MSFT]
    Developer Support
    ASP.NET


    This post is provided as-is with no warranties and confers no rights.

    --------------------
     
    Jim Cheshire [MSFT], Oct 16, 2003
    #6
  7. J.Marsch

    J.Marsch Guest

    Jim:

    Sorry that you haven't heard from me, I've been on a little bit of fire-duty
    lately.

    I think that I have the problem worked out. I had to set the initial size
    of the label (it evaluated as empty before). I haven't tried changing the
    width settings to 100% rather than trying to match the current width of the
    container. I expect that will probably help as well.

    Thanks for your help.

     
    J.Marsch, Oct 16, 2003
    #7
  8. J.Marsch

    J.Marsch Guest

    Jim:

    Sorry that you haven't heard from me, I've been on a little bit of fire-duty
    lately.

    I think that I have the problem worked out. I had to set the initial size
    of the label (it evaluated as empty before). I haven't tried changing the
    width settings to 100% rather than trying to match the current width of the
    container. I expect that will probably help as well.

    Thanks for your help.

     
    J.Marsch, Oct 16, 2003
    #8
  9. J.Marsch

    J.Marsch Guest

    Jim:

    Sorry that you haven't heard from me, I've been on a little bit of fire-duty
    lately.

    I think that I have the problem worked out. I had to set the initial size
    of the label (it evaluated as empty before). I haven't tried changing the
    width settings to 100% rather than trying to match the current width of the
    container. I expect that will probably help as well.

    Thanks for your help.

     
    J.Marsch, Oct 16, 2003
    #9
  10. Jeremy,

    No problem. I know how it goes. If you need more help, just post back.

    Jim Cheshire [MSFT]
    Developer Support
    ASP.NET


    This post is provided as-is with no warranties and confers no rights.

    --------------------
    <>
    <>
     
    Jim Cheshire [MSFT], Oct 17, 2003
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.