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

Conflict with column names of server bound grid and input controls with the same names on the page

7 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Todor
Top achievements
Rank 1
Todor asked on 02 Jan 2011, 10:55 PM
Hi,

I experienced the following problem. I have a page with a server bound grid with some data fields, and a form with input controls which I would like to display values of the fields of a selected record for edit and next to submit. The names of these controls follow the names of the data fields (which are also the same as the columns of the grid). However when the page is displayed, input controls always are initialized with values of the last record displayed within the server side bound grid, regardless of what values these controls are set to display.

Here is a isolated code snippet: 

<body>
    <% Html.Telerik().Grid((IEnumerable<MyData>)ViewData["Data"])
           .Name("Grid")
             
           .DataKeys(keys =>
               keys.Add(key => key.RecID)
           )
           .Columns(cols => {
               cols.Bound(col => col.RecID);
               cols.Bound(col => col.Data1);
               cols.Bound(col => col.Descr);
           })           
           .Render();
    %>
  
<% using(Html.BeginForm("SaveEditedData", "Home")) { %>
<div>
    <div>
       <%= Html.Telerik().IntegerTextBox()
                .Name("RecID")                          
                .Value(2)                                                 
                .EmptyMessage(null)                
            %> 
    </div>
    <div 
        <%= Html.Telerik().IntegerTextBox()
                .Name("Data1")                          
                .Value(5)                                                 
                .EmptyMessage(null)                
            %>            
    </div>    
</div>
<% } %>    
  
    <% Html.Telerik().ScriptRegistrar()          
            .Render(); %>
</body>

If you run the above code snippet, controls for RecID and Data1 fields will display initially the values of the last record that is visible in the grid control, instead to display 2 and 5.
In the above snippet I use only Telerik's IntegerTextBox controls, but it my actual implementation (which is more complex)  the same issue also was experienced when is used Telerik's DatePicker control and standard TextBox control from the System.Web.Mvc library (in that code sample I couldn't reproduce this behaviour with standard TextBox control).

Actually, I can change the names of the input controls to be not the same as the names of the data columns (data fields), and the problem will  go away, but this will introduce a complexity later with automatic model binding when the form is submitted, i.e. need writing either of a custom ValueProvider or a custom ModelBinder. 

Would you confirm if this is a bug, or is some limitation of using which need to be considered in implementations.

Kind regards
Todor Mihailov 

7 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 03 Jan 2011, 05:59 PM
Hello Todor,

Thank you for drawing our attention to this issue.

I confirm it as a bug, which I am glad to inform you will be fixed for the  next official release of the Telerik Extensions for ASP.NET MVC. Currently you can use this code snippet as a workaround:

<%= Html.Telerik().NumericTextBox()
        .Name("RecID")
        .InputHtmlAttributes(new {value = 1})
%>


I have updated your Telerik points.

Best wishes,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Todor
Top achievements
Rank 1
answered on 04 Jan 2011, 09:21 PM
Hello Georgi,

Your suggested workaround works fine for IntegetTextBox, and for standart TextBox extention, but the same issue also appears with DatePicker extention, where this workaround doesn't help, i.e. a value set directly through InputHtmlAttributes method of DatePicker extention, like:

<%= Html.Telerik().DatePicker()
                   .Name("DocDate")
                   .InputHtmlAttributes(new { value = "02.05.2009"})
            %>

 is overwritten later when the page is rendered due to this bug in the grid.
 
Do you have a suggestion for DatePicker extention also? I'm not sure if you can reproduce the bug using my code snippet below and a DatePicker extention, but in my actual implementation I can confirm it appears with DatePicker also. 

Kind regards
Todor Mihailov
0
Georgi Krustev
Telerik team
answered on 05 Jan 2011, 10:32 AM
Hello Todor,

On my end, suggested workaround with InputHtmlAttributes method works as expected. I have set predifined value with the following code snippet:

<%= Html.Telerik().DatePicker().Name("OrderDate").InputHtmlAttributes(new { value ="2/2/2000"})%>

If the problem still persists I will suggest you send us a simple test project.

Kind regards,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Todor
Top achievements
Rank 1
answered on 05 Jan 2011, 08:40 PM
Hello Georgi,

Please find attached a simple test project describing the problem. I am using version 2010.3.1110

Kind regards
Todor Mihailov
0
Georgi Krustev
Telerik team
answered on 06 Jan 2011, 12:52 PM
Hello Todor,

 
Thank you for the sample project.

I was able to observe the aforementioned erroneous behavior. Unfortunately using InputHtmlAttributes will not resolve the limitation which you hit. The only feasible solution which I can suggest for now is to use JavaScript and  set date on client. Here is a code snippet showing what I mean:

function datepicker_load(e) {
    $(this).data('tDatePicker').value("02/02/2007");
}

For your convenience I have attached the modified test project.

Also I need to note that this issue will be fixed in the next official release of Telerik Components for ASP.NET MVC.


Kind regards,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Todor
Top achievements
Rank 1
answered on 22 Jan 2011, 12:37 PM
Hello Georgi,

I installed the latest release v.2010.3.1318 and expected this issue to be fixed (as it states in the Release Notes), but unfortunately it seems it's partially fixed.

Indeed it works for TextBox, IntegerTextBox and DatePicker now, but only if it is set a value for these controls, if it is set a value of null, or not set value at all, these controls still display values of the last record displayed in the grid.

As for DropDownList control, the fix does not work at all - it neither works when it is selected an item (using SelectedIndex method), nor when it is not selected an item.

I am attaching a test project

Thanks in advance

Kind regards
Todor Mihailov
0
Georgi Krustev
Telerik team
answered on 24 Jan 2011, 03:40 PM
Hello Todor,

The aforementioned behavior is actually expected. As you can see in your test project, Html.TextBox component gets the value from ViewData dictionary when defined value is NULL. Telerik NumericTextBox component ( NumericTextBox, IntegerTextBox, CurrencyTextBox, PercentTextBox ) works in the same way.
You can use InputHtmlAttributes if you need to clear input value.

As to the ComboBox component, the situation is the same. Value get from ViewData prevails over selected index. This is the expected behavior. If you need to overcome this behavior you can wire load event of the ComboBox and pre-select desired item. For more information check ComboBox client API help topic.

Regards,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Todor
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Todor
Top achievements
Rank 1
Share this question
or