Using @helper in Window widget not working

5 posts, 0 answers
  1. Mike
    Mike avatar
    5 posts
    Member since:
    Nov 2015

    Posted 03 Nov 2015 Link to this post

    Hello,

    I’m trying to use a @helper inside a Telerik Window widget but it doesn’t work as expected. If I use the @helper then it shows the TextBox widget in the main page without opening/showing the Window widget but the labels are shown as expected however if I write the code in the @helper directly in the Window widget then it works as expected. Why this strange behavior?

    Here's the code

     ​

    01.@helper MakeTextBox1(string name, string description)
    02.{
    03.    <li>
    04.        <label for="@name">@description</label>
    05.        @{
    06.            var x = Html.Kendo().TextBox()
    07.                .Name(@name);
    08. 
    09.            x.Render();
    10.        }
    11.    </li>
    12.}
    13. 
    14.@(Html.Kendo().Window()
    15.    .Name("window_CreateProduct")
    16.    .Title("Product")
    17.    .Content(@<text>
    18.        <div style="text-align: center;">
    19.            <form id="form">
    20.                <ul class="fieldlist">
    21. 
    22.                    // Doesn't work
    23.                    @MakeTextBoxNumeric1("amount", "Amount")
    24. 
    25.                    // It works!
    26.                    <li>
    27.                        <label for="numeric_Price">Price: </label>
    28.                        @(Html.Kendo().NumericTextBox()
    29.                            .Name("numeric_Price")
    30.                        )
    31.                    </li>
    32.                </ul>
    33.            </form>
    34. 
    35.        </div>
    36.    </text>)
    37.    .Draggable()
    38.    .Visible(false)
    39.    .Modal(true)
    40.    .Resizable(x => x.Enabled(false))
    41.    .Events(x => x.Open("onOpen_window"))
    42.)

     

    Can anyone help me to solve this?

     Thank you.

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 05 Nov 2015 Link to this post

    Hello,

    The texfbox will be shown outside of the window because you are using the Render method which writes directly to the view. You should either use the Render method for the window and its action overload for the Content method or not use the Render method for the textbox:
    @helper MakeTextBox1(string name, string description)
    {
        <li>
            <label for="@name">@description</label>
            @Html.Kendo().TextBox().Name(name)
        </li>
    }


    Regards,
    Daniel
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Mike
    Mike avatar
    5 posts
    Member since:
    Nov 2015

    Posted 05 Nov 2015 in reply to Daniel Link to this post

    Hello Daniel,

    I need to use the Render method in the @helper because I've an if statement to add some HTML attributes depending on the conditions. What I showed you here is a simplified version of the problem.

    I've tried the overloaded versions of Content as you suggested but I can't get it working. I don't know how to use @helper in the overloaded versions of Content.

    Can you please write a simple call to .Content using the @helper?

    This is the old method opening the Window

    1.var window = $("#window");
    2. 
    3.$("#btn_open").bind("click", function () {
    4.    window.data("kendoWindow").center().open();
    5.});

    I replaced .open with .render . Is this correct?

    Thank you for your help

    Mike.

  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 06 Nov 2015 Link to this post

    Hello,

    You can define the helper in a code block and still output it without the Render method:
    @{
        var x = Html.Kendo().TextBox()
            .Name(@name);
        ...
    }
    @x

    As for using the Window Render method - I meant the Render method of the helper:
    @{Html.Kendo().Window()
        ...
        .Render();
    }
    It seems that using the Action overload is not needed in this case so you can use the same code for the Content method.


    Regards,
    Daniel
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Mike
    Mike avatar
    5 posts
    Member since:
    Nov 2015

    Posted 11 Nov 2015 in reply to Daniel Link to this post

    Thank you Daniel it works now!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready