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

Best practice for disabling javascript postback problem?

1 Answer 196 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 03 Mar 2011, 12:50 AM
Hi Telerik,

So, I encountered the issue where I would change a RadComboBox's selection programmatically client-side and it would trigger a postback when unwanted.

I came up with this solution, but I do not know if this is best practice. If not, what other options do I have? If so, cheers to anyone else who can use it.

1) Turn RadComboBox autopostback to false.

<script type="text/javascript">
    var doPostback = true;
    function pageLoad() {
        doPostback = false;
        $find("<%= RadComboBox1.ClientID %>").findItemByValue("YourItemHere").select();
        doPostback = true;
     }
 
      function OnClientSelectedIndexChanged(sender, eventArgs) {
          if (doPostback) {
              __doPostBack('RadComboBox1', '');
          }
     }
 </script>

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Mar 2011, 11:05 AM
Hello Sean,

You should be able to accomplish this scenario with the help of RadAjaxManager as well.

aspx:
<telerik:RadAjaxManager  ID="RadAjaxManager1"  runat="server"  OnAjaxRequest="RadAjaxManager1_AjaxRequest">
</telerik:RadAjaxManager>

JavaScript:
function postBack(sender, args)
   var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
  ajaxManager.ajaxRequestWithTarget('<%= RadComboBox1.UniqueID %>', '');
}

And also check this code library which follows the __doPostBack method for raising the postback..
RadComboBox - Allow only certain items to postback

Thanks,
Shinu.
Tags
ComboBox
Asked by
Sean
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or