locked
can't resize in design mode RRS feed

  • Question

  • User192013029 posted

    writing a composite control that is similar to the one i asked about a few weeks back. in that one, i placed all child controls in a TableCell based container control and rendered the containers. there was no problem related to resizing the control in design mode - it worked from the beginning and without the need for a CustomControlDesigner class with an overridden AllowResize method. to render i used the RenderContents method.

    now i'm doing a very similar control but for readability reasons, have taken out the container stuff and am now rendering the controls in the Render method rendering the appropriate table, tr and td tags around them (since the container controls in the old version were based on a table cell where a table control was rendered automatically, i figured i now needed to create my own table surrounding the child controls to get the same effect). well, the new control draws ok in design mode and i even get the resize squares on each side and corner but it won't let me resize it. the size stays fixed. here's a list of the key things i'm doing..

     

            protected override void CreateChildControls()
            {
                Controls.Clear();
    
    // create the controls, set their Height, Width, Text, Id properties 
    // and add to Controls collection.
    
            protected override void Render(HtmlTextWriter writer)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Table);
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
                writer.AddAttribute(HtmlTextWriterAttribute.Valign, "middle");
                writer.AddAttribute(HtmlTextWriterAttribute.Style, "color: Black; background-color: White; font-weight: normal;");
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                button1.RenderControl(writer);
    // etc
    

    in the original control, i did creates on both the controls and their corresponding containers and used RenderContents to render the containers. so whats the difference? what i'm doing now seems like the equivalent.

    note: overriding AllowResize in the designer class did not work. 

    Tuesday, June 16, 2009 3:44 PM

Answers

  • User192013029 posted

    well, i don't remember what i did or didn't do to make me think that using RenderContents didn't work with the new control (i know i tried it) but trying it again just now did work. one key thing i discovered a couple days ago was that i was overriding the TagKey property. this guy is important in that it returns (to the best of my understanding) the html tag within which your rendered content will be written to. it is called by the AddAttributesToRender method which in turn is called by RenderContents underneath the covers. this is why Render didn't work before adding the call AATR - Render doesn't automatically call AATR as RC does. really confusing. wish there was better documentation describing the differences between these different Render methods because i'm still seeing some weird behavior when trying different things.

    but anyway, here's what i have now which works..

            protected override HtmlTextWriterTag TagKey
    {
    get { return HtmlTextWriterTag.Table; }
    }

    protected override void CreateChildControls()
    {
    Controls.Clear();
    // create controls, set properties and add
    // to Controls collection

    ChildControlsCreated = true;
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
    //AddAttributesToRender(writer); // need if using Render

    //writer.RenderBeginTag(HtmlTextWriterTag.Table); // need if using Render (end tag as well)

    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
    writer.AddAttribute(HtmlTextWriterAttribute.Valign, "middle");
    writer.AddAttribute(HtmlTextWriterAttribute.Style, "color: Black; background-color: White; font-weight: normal;");
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    button1.RenderControl(writer);
    // etc
    }

    the resulting html looks like this..

     

        <div>  <!-- in original aspx markup -->
    <!-- table tag generated by TagKey method -->

    <table id="MyXMLViewer21" style="height: 348px; width: 338px;">
    <!-- tr's and td's generated by RenderContents method -->
    <tr>
    <td align="left" valign="middle" style="color: Black; background-color: White; font-weight: normal;">
    <input type="submit" name="MyXMLViewer21$SwapViewButton" value="Swap View" id="MyXMLViewer21_SwapViewButton"
    style="color: Maroon; height: 25px; width: 100%;" />
    </td>
    <td align="right" valign="middle" style="color: Black; background-color: White; font-weight: normal;">
    <input type="submit" name="MyXMLViewer21$SaveXMLButton" value="Save XML" id="MyXMLViewer21_SaveXMLButton"
    style="color: Maroon; height: 25px; width: 100%;" />
    </td>
    </tr>
    </table>
    </div>
      
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 19, 2009 8:16 AM

All replies

  • User192013029 posted

    looking at an example on the internet that did things exactly as i did, i noticed that a call to AddAttributesToRender was being made at the top of the Render method. when i added this to my code, i could now resize the control. cool. but i still don't know why it works..

    does anybody know why calling this method enabled the resize?

    Wednesday, June 17, 2009 11:16 PM
  • User-2106054853 posted

    Hi,

    Please upload a demo project to:http://skydrive.live.com/

    and paste the download link here for me to repro.

     

    Thursday, June 18, 2009 5:28 AM
  • User192013029 posted

    well, i don't remember what i did or didn't do to make me think that using RenderContents didn't work with the new control (i know i tried it) but trying it again just now did work. one key thing i discovered a couple days ago was that i was overriding the TagKey property. this guy is important in that it returns (to the best of my understanding) the html tag within which your rendered content will be written to. it is called by the AddAttributesToRender method which in turn is called by RenderContents underneath the covers. this is why Render didn't work before adding the call AATR - Render doesn't automatically call AATR as RC does. really confusing. wish there was better documentation describing the differences between these different Render methods because i'm still seeing some weird behavior when trying different things.

    but anyway, here's what i have now which works..

            protected override HtmlTextWriterTag TagKey
    {
    get { return HtmlTextWriterTag.Table; }
    }

    protected override void CreateChildControls()
    {
    Controls.Clear();
    // create controls, set properties and add
    // to Controls collection

    ChildControlsCreated = true;
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
    //AddAttributesToRender(writer); // need if using Render

    //writer.RenderBeginTag(HtmlTextWriterTag.Table); // need if using Render (end tag as well)

    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
    writer.AddAttribute(HtmlTextWriterAttribute.Valign, "middle");
    writer.AddAttribute(HtmlTextWriterAttribute.Style, "color: Black; background-color: White; font-weight: normal;");
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    button1.RenderControl(writer);
    // etc
    }

    the resulting html looks like this..

     

        <div>  <!-- in original aspx markup -->
    <!-- table tag generated by TagKey method -->

    <table id="MyXMLViewer21" style="height: 348px; width: 338px;">
    <!-- tr's and td's generated by RenderContents method -->
    <tr>
    <td align="left" valign="middle" style="color: Black; background-color: White; font-weight: normal;">
    <input type="submit" name="MyXMLViewer21$SwapViewButton" value="Swap View" id="MyXMLViewer21_SwapViewButton"
    style="color: Maroon; height: 25px; width: 100%;" />
    </td>
    <td align="right" valign="middle" style="color: Black; background-color: White; font-weight: normal;">
    <input type="submit" name="MyXMLViewer21$SaveXMLButton" value="Save XML" id="MyXMLViewer21_SaveXMLButton"
    style="color: Maroon; height: 25px; width: 100%;" />
    </td>
    </tr>
    </table>
    </div>
      
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 19, 2009 8:16 AM