How to get width of the element in render and postRender method RRS feed

  • Question

  • HI All,

    I am new to lightswitch html.

    I have created a custom control and i am rendering in _render method.          


    myapp.Home.Group_render=function (element, contentItem) {    // Write code here.             var control = $("<div></div>").attr('id', "container1");  

      control.appendTo($(element));    control.chart(); };

      My control is about to draw a graph, so i need to assign width for my control.  so i have tried to get width of the div ("container1"), but it returning zero, then tried for parent, that is element, but no luck, i am again getting zero.


    But after rendering my control with some static width, i can able to see the width for the element (msls-ctl-group-custom-control) in dom, which is less than my static value, so my control is showing out of the element div. 

    How to get the width of the element in _render method itself

    Thanks in advance

    Friday, April 15, 2016 5:44 AM


  • Hi Gowri_123,

    According to your description, I create a sample project to try get the width for the element, but the value for this control always 0.

    Since the postRender and render method are used to load the control itself and before this method finished, the control is not loaded complete. And the same result in created method, which is not load the screen finished. This is why we can't get the value of the control's width.

    When you use DOM to check your control, the screen and all controls on this screen have been loaded complete.

    If you want to get a control's width, please in an event which after the screen loaded. For example, a button's execute event. Please refer to following code.

    myapp.BrowseCustomers.Method_execute = function (screen) {
        var btn = $("#container1").width();

    Best Regards,

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Click HERE to participate the survey.

    Tuesday, April 19, 2016 8:39 AM