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

Combobox Postback?

3 Answers 47 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 22 May 2012, 07:28 PM
Okay I must be missing something simple...

I have a combo box on my page and it is loaded with the telerik themes. The intent is to allow the user to change the theme and have the site update as soon as the theme is selected. Here is my controller code:

public ActionResult Index(ThemeComboBoxModel model)
{
    ViewBag.Message = "Welcome to Contoso University!";
 
    model.DropDownListAttributes.Width = model.DropDownListAttributes.Width ?? 200;
    model.DropDownListAttributes.SelectedIndex = model.DropDownListAttributes.SelectedIndex ?? 0;
    model.DropDownListAttributes.SelectedValue = model.DropDownListAttributes.SelectedValue ?? "telerik.Default.css";
    model.Themes = _LoadThemeList();
 
    _Profile.Theme = model.DropDownListAttributes.SelectedValue;
    ViewBag.Theme = _Profile.Theme;
 
    return View(model);
}

Here is my view code:

@(Html.Telerik().DropDownList()
.Name("DropDownListTheme")           
.SelectedIndex(Model.DropDownListAttributes.SelectedIndex.Value)           
.BindTo(new SelectList(Model.Themes, "ThemeId", "ThemeName"))           
.HtmlAttributes(new { style = string.Format("width:{0}px", Model.DropDownListAttributes.Width) }) 
)
       
@using (Html.Configurator("The DropDownList should...")
    .PostTo("Index", "Home")
    .Begin())
{
}

When the selection is changed, I would like it to fire off the Index method in the Home Controller again, and I thought it would due to the .PostTo line on the HtmlConfigurator but nothing happens when the selection is changed. What am I missing?

Thanks!!







3 Answers, 1 is accepted

Sort by
0
jfkrueger
Top achievements
Rank 1
answered on 22 May 2012, 10:38 PM
I can easily add a button and include it in a form to make this work but I would rather not force the user to click a button, I would much rather have the code fire when the selection in the drop-down changes. Any way to do this?

Thanks!
0
jfkrueger
Top achievements
Rank 1
answered on 23 May 2012, 02:16 PM
It would be great to use theme drop-down from the examples but I am unable to get it to work in my project. All that shows up is a box with the word "Vista" in it, no drop-down. I have copied over all of the CSS as well as the telerik.examples.min.js file and I have used the same code as in the examples:

<div id="theming"><a href="#" class="t-drop-down">@Html.GetCurrentTheme()</a></div>
<script type="text/javascript">
    var currentComponent = '@ViewContext.RouteData.Values["Controller"]',
        themePreviewsLocation = '@Url.Content("~/Content/Images/Themes")';
</script>

I must just be missing another piece. The script is never getting executed and I am not seeing how it is even ever called on the example site. Any clue as to what I am missing?

Thanks!
0
jfkrueger
Top achievements
Rank 1
answered on 23 May 2012, 04:10 PM
Update: Okay I have everything working. Needed to copy the stylesheet from the example and add this to my shared layout:
@(Html.Telerik().ScriptRegistrar()
                     .DefaultGroup(group => group
                         .Add("telerik.examples.js")
                         .Compress(true))
                     .OnDocumentReady(
                     @<text>
                         prettyPrint();
                     </text>)
    )

Now if I could just get it to work with the profile (persisting theme and loading theme)... I will open another post for that.
Tags
ComboBox
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
jfkrueger
Top achievements
Rank 1
Share this question
or