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

PostBack-behaviour with dynamic populate

1 Answer 103 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Linus
Top achievements
Rank 2
Linus asked on 23 Mar 2009, 08:36 AM
Hello all!

First i'll describe my scenario:

I have a grid with a ComboBox on each row. It displays an index-value, kind of it's position. When the grid is databound i'll simply set the text-value of the ComboBox to the current index (for display purposes). It's possible to change this index by clicking on the ComboBox and as you probably understand this is where the ComboBox gets populated through the OnItemsRequested-event. Everything looks good and works fine, however, if the ComboBox is clicked -> items get requested -> and after the ComboBox has been populated and the user clicks somewhere else on the page, the ComboBox will AutoPostback, allthough no item was clicked... Frustrating behaviour since PostBack only should occur when another item is clicked.

At the moment i'm trying so solve this with some client-side code, not finished tho. Any ideas or recommendations?

1 Answer, 1 is accepted

Sort by
0
Linus
Top achievements
Rank 2
answered on 23 Mar 2009, 09:31 AM
I solved it using client-side code and attributes and thought that others might have use for it. Basically, every requested item has an attribute identifying the original position. The PostBack is stopped if the selected value equals the original value.

<telerik:RadScriptBlock ID="RSB" runat="server"
 
<script language="javascript" type="text/javascript">     
    function OnClientSelectedIndexChanging(sender, eventArgs) { 
         
        // check item 
        var item = eventArgs.get_item();         
        if(item) {             
            var itemOrderInt = parseInt(item.get_attributes().getAttribute("ItemOrder")); 
            var itemValueInt = parseInt(item.get_value()); 
 
            if (itemOrderInt == itemValueInt) 
                eventArgs.set_cancel(true);                                     
        } 
    } 
</script>  
 
</telerik:RadScriptBlock>    

Good luck :)
Tags
ComboBox
Asked by
Linus
Top achievements
Rank 2
Answers by
Linus
Top achievements
Rank 2
Share this question
or