custom text exact match on client selected ondex changed event

6 posts, 0 answers
  1. Hari Prasad
    Hari  Prasad avatar
    16 posts
    Member since:
    Feb 2010

    Posted 26 Jun 2012 Link to this post

    Hi,

    I have combo box, im loading the item on load demand. I have client selected index changed event, if i type exact text(case sensitive) and when i come out of the combobox and clicked on out side of the combobox,onclientselectedindexchanged event is firing. I don't want to fire this event when exact match is found. I want user to select the item from the combobox list then only i want this event to be fire.

    I have

    MarkFirstMatch

     

    ="false"

     

    Attachment1 is firing the event.
    Attachment2 is not firing the event.
    Please let me know the solution for this. If this is the default behaviour of the combobox, are there any work arounds for the solution.

    Thanks in Advance,
    Hari.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Jun 2012 Link to this post

    Hi,

    Try the following Javascript to achieve your scenario.

    JS:
    <script type="text/javascript" >
       function OnClientBlur(sender, args)
        {
          sender.clearSelection();
        }
    </script>

    Thanks,
    Princy.
  3. Hari Prasad
    Hari  Prasad avatar
    16 posts
    Member since:
    Feb 2010

    Posted 26 Jun 2012 Link to this post

    Hi Princy,

    Thanks for your quick reply.

    Is it possible to do without clearing the selection. I have typed "dotnet se" and i will come out of the combobox, then its clearing the combobox item. I would like to be text should exist in the combo box when i come out of the combo box.

    Thanks in Advance,
    Hari.
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Jun 2012 Link to this post

    Hi HariPrasad,

    Yes its possible without clearing the selection as well.
    Try the following JS and it worked as expected.First add a asp:hiddenfield to the aspx
    aspx:
    <asp:HiddenField ID="HiddenField1" runat="server" />
    JS:
    <script type="text/javascript">
    function OnClientBlur()
     {
       var combobox = $find('<%=RadComboBox1.ClientID%>');
       var combotxt = combobox._text;
       var items = combobox.get_items();
       var itemsCount = items._array.length;
       for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++)
       {
          var itemtxt = items._array[itemIndex]._text;
          if (combotxt == itemtxt)
          {
            var hidfield = document.getElementById('<%=HiddenField1.ClientID%>');
            hidfield.value = "1";
          }
     
        }
     }
     
    function OnClientSelectedIndexChanged()
      {
        var hidfield = document.getElementById('<%=HiddenField1.ClientID%>');
        if (hidfield.value == "1")
         {
           return false;
         }
         else
         {
           //your code......
         }
      }
    </script>

    Thanks,
    Princy.
  5. Hari Prasad
    Hari  Prasad avatar
    16 posts
    Member since:
    Feb 2010

    Posted 27 Jun 2012 Link to this post

    It worked. Thanks for your help.
    If we type exact match, then Combobox client selected index changed event is firing. Is this the Default behaviour of the Rad Combo Box?

    Thanks,
    Hari.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Jun 2012 Link to this post

    Hi HariPrasad,

    You can cancel the OnClientSelectedIndexChanging event as follows which doesn't allow to fire OnClientSelectedIndexChanged event of RadComboBox.

    JS:
    <script type="text/javascript">
        function OnClientBlur() {
            var combobox = $find('<%=RadComboBox1.ClientID%>');
            var combotxt = combobox._text;
            var items = combobox.get_items();
            var itemsCount = items._array.length;
            for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++) {
                var itemtxt = items._array[itemIndex]._text;
                if (combotxt == itemtxt) {
                    var hidfield = document.getElementById('<%=HiddenField1.ClientID%>');
                    hidfield.value = "1";
                }
            }
        }
        function OnClientSelectedIndexChanging(sender,args) {
            debugger;
            var hidfield = document.getElementById('<%=HiddenField1.ClientID%>');
            if (hidfield.value == "1") {
                hidfield.value = "0";
                args.set_cancel(true);
                return false;
            }
            else {
                //your code......
            }
        }
    </script>

    Hope this helps.

    Thanks,
    Princy.
Back to Top