This is a migrated thread and some comments may be shown as answers.

Using @helper in Window widget not working

4 Answers 49 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 03 Nov 2015, 05:28 PM

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.

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 05 Nov 2015, 12:27 PM
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
0
Mike
Top achievements
Rank 1
answered on 05 Nov 2015, 02:01 PM

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.

0
Daniel
Telerik team
answered on 06 Nov 2015, 12:06 PM
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
0
Mike
Top achievements
Rank 1
answered on 11 Nov 2015, 04:54 PM
Thank you Daniel it works now!
Tags
Window
Asked by
Mike
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mike
Top achievements
Rank 1
Share this question
or