Server side PostBack event on selecting Checkboxes under ComboBox

6 posts, 0 answers
  1. Paresh Dehadray
    Paresh Dehadray avatar
    4 posts
    Member since:
    Dec 2009

    Posted 11 Aug 2011 Link to this post

    Respected Sir/Madam,

    I need to show checkboxes in one ComboBox. Now I want Server Side postback event, when user selects all desired checkboxes and clicks outside of ComboBox to close the ComboBox window. Is it possible? Currently SelectedIndexChanged is not working in this case. 

    ASPX code:

     <telerik:RadComboBox runat="server" ID="ddlPopulation"  OnSelectedIndexChanged ="ddlPopulation_SelectedIndexChanged"
      OnItemDataBound="ddlPopulation_ItemDataBound" AllowCustomText="false" AutoPostBack="true" >
          <ItemTemplate>
                <asp:CheckBox runat="server" ID="chk"  />
          </ItemTemplate>
     </telerik:RadComboBox>


    C# code

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
      {
    PopulatePopulation();
      }
    }

     private void PopulatePopulation()
        {
            ddlPopulation.DataSource = Job.GetPopulations();
            ddlPopulation.DataTextField = "PopulationName";
            ddlPopulation.DataValueField = "PopulationID";
            ddlPopulation.DataBind();
        }

     protected void ddlPopulation_ItemDataBound(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e)
        {
            CheckBox chk = e.Item.FindControl("chk") as CheckBox;
            chk.Text = e.Item.Text;
        }

     protected void ddlPopulation_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
    //TODO: do some work
        }

    Please help me how can I get server side event. On this Event I need to populate one another ComboBox.

    Thanks
    Paresh


  2. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 11 Aug 2011 Link to this post

    Hi Paresh,

    If you do this, anytime someone checks any checkbox in the RadComboBox template you will be able to handle the event on the server side to bind the secondary RadComboBox.

    <ItemTemplate>
        <asp:CheckBox ID="chk" runat="server" OnCheckedChanged="chk_OnCheckChanged" AutoPostBack="true" />
    </ItemTemplate>

    protected void chk_OnCheckChanged(object sender, EventArgs e)
    {
        // Load secondary combobox
    }

    Hopefully I understood your requirements properly.
    Thad
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paresh Dehadray
    Paresh Dehadray avatar
    4 posts
    Member since:
    Dec 2009

    Posted 12 Aug 2011 Link to this post

    Hi,

    Thanks for your reply. I have already tried this. But I am not sure why full postback event is getting fired event after my controls are kept in UpdatePanels.

    Also I think this will be just a work around because in my case there are 300 checkboxes (in ComboBox) and server side event on each click will be costly. I need to populate other ComboBox on the basis of which checkboxes are selected.

    Is there any way by which I get only one Server Side event (when ComboBox window will be closed) and also get the information which checkboxes are checked. So that I can populate other ComboBox.

    Thanks
    Paresh
  5. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 12 Aug 2011 Link to this post

    Hi Paresh,

    I thought that would be too easy of an answer!  :-)

    I have several other suggestions, then.  Hopefully one of them will work for you.

    First, in JavaScript you can handle either the OnClientDropDownClosing or OnClientDropDownClosed and do a postback like so.  Then you can load the second dropdown in the SelectedIndexChanged method.  PS: Make sure you set AutoPostBack="false".
    __doPostBack(<%=ddlPopulation.UniqueID%>, '');

    Or if you prefer a callback and are using the RadAjaxManager, you can fire off an AjaxRequest and handle it on the server
    $find(<%=RadAjaxManager.GetCurrent(Page) %>).ajaxRequest("ProcessCheckedPopulations");
    // ramMain is a reference to your RadAjaxManager
    ramMain.AjaxRequest += RadAjaxManager_AjaxRequest;
     
    private void RadAjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "ProcessCheckedPopulations") {
            // Populate secondary dropdown
        }
    }

    Another option is to put a button in the FooterTemplate that the user clicks on when all selections are made.  If it's an ImageButton with a nice graphic it could be quite intuitive for your users.
    <FooterTemplate>
        <asp:Button ID="btnProcessCheckedPopulations" runat="server" OnClick="btnProcessCheckedPopulations_Click"
            Text="- Done -" />
    </FooterTemplate>

    Good luck!
    Thad
  6. Paresh Dehadray
    Paresh Dehadray avatar
    4 posts
    Member since:
    Dec 2009

    Posted 12 Aug 2011 Link to this post

    Thanks Thad.
    You are excellent. FYI, I chose 2nd solution (RadAjaxManager). I am not sure how it is working and how it maintains value during postback but it is working.

    Regards
    Paresh
  7. Paresh Dehadray
    Paresh Dehadray avatar
    4 posts
    Member since:
    Dec 2009

    Posted 20 Aug 2011 Link to this post

    Hello Thad,

    Hope you are doing well.
    In this post as suggested by you, I had selected callback option by using RadAjaxManager. But some how I was not able to implement this. Currently in my Project I am using Telerik as well as AjaxControlToolkit new version. When I keep ToolkitScriptManager on Master page then RadAjaxManager is not working properly.

    So I selected your second option __doPostBack(<%=ddlPopulation.UniqueID%>, '');
    By this I am getting server side postback without full page refresh ( as I am using UpdatePanel)

    But I am not getting ddlPopulation_SelectedIndexChanged server side event.
    Is there any way so that by __doPostBack I directly get server side ddlPopulation_SelectedIndexChanged event?

    As work around, currently I am using server side HiddenField control. By javascript before calling __doPostBack I set HiddenField value and on PostBack I check if HiddenField value is set then I call ddlPopulation_SelectedIndexChanged function manually.

    Is it the only way to work with __doPostBack? Please suggest.
    How Microsoft Control raise event and call events function?

    Thanks
    Paresh




Back to Top
UI for ASP.NET Ajax is Ready for VS 2017