ViewData[
"SampleList"] = new SelectList(data, "Name", "Name");
In my View, I access my ViewData and bind it to the combobox
<%
= Html.Telerik().ComboBoxFor(model => model.name)
.BindTo((SelectList)ViewData["SampleList"]) %>
This codes works. The problem is that whenever I input any data(not available in the provided list) in my combobox, after submiting a form or any triggering a postback, the value becomes lost and resets back.
What I want to achieve here is that even though there is a given list, I want the user to have the flexibility to input what ever they want.
Please advice
5 Answers, 1 is accepted
I believe that the ComboBox UI component will preserve user's input through PostBacks. You can test it on this online demo.
If you need to add custom text to the list of items, then you should new item to the SampleList collection on PostBack.
Georgi Krustev
the Telerik team
Thanks for the response.
I was able to visit the sample, but still I can see why is it not working in my solution. I even tried using only
<%= Html.Telerik().ComboBoxFor(model => model.name) %>
I did not even bind my viewData, upon debugging, model.name has "Barry" value. But upon rendering of page, the value does not appear.
I am using telerik version 2010.3.1110.235. If possible, can you please make a sample project where I can refer? Make it short and simple, just show how could I persist data in the comboBoxFor.
Please advice
Persisting values from PostBack is not supported in 2010.3.1110 version. I will suggest you upgrade to the latest official version of Telerik Components for ASP.NET MVC.
As to the demo, our online demos are distributed with the Telerik Components for ASP.NET MVC. You can download them and refer to the ComboBox/ClientValidation.aspx page. It shows how simply and really straightforward to achieve your goal.
Georgi Krustev
the Telerik team
I downloaded the latest version for MVC 2 version 2010.3.1318.235. I referred to the samples that are available but unfortunately I observed that the values only persist after I give focus to the combo box. Please see attached screenshot.
Anyway, I was able to fix this by modifying the telerik.combobox.min.js. I just repopulated the textbox when initializing the textbox
var p = this
var o = this
if
this
}
Unfortunately I am still not able to reproduce the depicted issue on our online demo, which runs upon version 2010.3.1318 of the Telerik Components for ASP.NET MVC. If the problem still persists I will suggest you send us a simple test project, where we can observe the depicted issue.
Georgi Krustev
the Telerik team