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

DataBind on button click not working

3 Answers 279 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 30 Mar 2010, 04:13 PM
I'm having trouble re- DataBinding a combobox on a button click event.  On the initial page load I'm binding the combobox (this works fine) which holds report settings.  I'm allowing the user to type in a value on the combobox which enables a save link button.  When the user clicks on the link button, I save all the report criteria off to the database and want to DataBind the combobox so show the newly added Item to the list.  I've debugged the process and show that the new item is getting saved off to the database,  the database is returning all items (including newly added).  It also appears that new item is getting bound to the combobox but it does not display in the browser.

Aspx:
                <table border="0" cellpadding="0" cellspacing="0" style="background-color:White;">              
                <tr> 
                    <td style="padding-right:5px;"><asp:LinkButton ID="lnkbtnSave" runat="server" Enabled="false" OnClick="lnkbtnSave_Click">Save</asp:LinkButton></td>  
                    <td style="padding-right:5px;"><asp:LinkButton ID="lnkbtnSaveAs" Enabled="false" runat="server" OnClick="lnkbtnSave_Click">Save As...</asp:LinkButton></td>  
                    <td><telerik:RadComboBox ID="rcbRptSettings" runat="server" AllowCustomText="true" EmptyMessage="My Reports" LoadingMessage="Loading..." OnSelectedIndexChanged="rcbRptSettings_SelectedIndexChanged" AutoPostBack="true" Skin="Outlook" Width="250px"></telerik:RadComboBox></td>  
                    <td style="padding-left:5px;"><asp:LinkButton ID="lnkbtnDelete" runat="server" OnClientClick="return blockConfirm('Are you sure you want to delete this report?', event, 330, 100,'','AARates Delete My Report');" OnClick="lnkbtnDelete_Click" Enabled="false">Delete</asp:LinkButton></td>  
                </tr> 
                </table> 

Code behind:
        protected void Page_Load(object sender, EventArgs e)  
        {  
    
            if (!Page.IsPostBack)  
            {  
                BindSavedSettings(Master.loggedUser.UserReports);  
            }  
 
                              
        }  
 
        private void BindSavedSettings(List<UserReport> urReports)  
        {  
            rcbRptSettings.DataSource = urReports; //Master.loggedUser.UserReports;  
              
            rcbRptSettings.DataTextField = "Name";  
            rcbRptSettings.DataValueField = "UserReportID";  
            rcbRptSettings.DataBind();  
            rcbRptSettings.Items.Insert(0, new RadComboBoxItem("", ""));  
 
        }  
 
        protected void lnkbtnSave_Click(Object sender, EventArgs e)  
        {  
            //Saves existing report  
            bool settingsfound = false;  
            UserReport ursettings;  
            PgMessage.ClearMessages();  
 
            if (rcbRptSettings.Text != string.Empty)  
            {  
                //USED FOR GRID SETTINGS  
                //string grsettings = string.Empty;  
                //GridSettingsPersister persister = new GridSettingsPersister(ARGrid1);  
                //grsettings = persister.SaveSettings();  
 
                foreach (UserReport ur in Master.loggedUser.UserReports)  
                {  
                    if (ur.Name == rcbRptSettings.Text)  
                    {  
                        settingsfound = true;  
                    }  
                }  
                if (settingsfound)  
                {  
                    ursettings = UserReport.getByKey(Convert.ToInt32(rcbRptSettings.SelectedValue));  
                    SaveReportSettings(ursettings);  
                }  
                else  
                {  
                    //NEW Report Settings
                    ursettings = new UserReport();  
                    SaveReportSettings(ursettings);  
 
                    List<UserReport> urpt = UserReport.getByUserid(Master.loggedUser.Userid);  
                    BindSavedSettings(urpt);  //BindSavedSettings to add new report setting  
 
                }  
            }  
            else  
            {  
                PgMessage.DisplayMessage(PageMessage.MessageType.Information, "Report Setting name must be entered");  
            }  
 
 
        } 

3 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 31 Mar 2010, 03:05 PM
I think I've figured this one out. The problem had to do with Ajax.  Once I set up the AjaxManagerProxy for the button to update the combobox everything worked.  I'm still trying to figure out the Ajax stuff. Seems that if a control is set up to update a second control, the second control has to be setup in AjaxManageProxy to effect any controls it my change in the code behind.
0
Simon
Telerik team
answered on 01 Apr 2010, 09:34 AM
Hello Michael,

There is a subtle difference between RadAjaxManager and RadAjaxManagerProxy and you can read about each of these here and here.

Kind regards,
Simon
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
Velmurugan
Top achievements
Rank 1
answered on 16 Jul 2010, 02:12 PM
Hi

I am working with telerik:RadWindowManager. The Blockconfirm is working fine in outside of grid. but it is not working inside the grid. please help me in needful.

Thanks
Vel
Tags
ComboBox
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Simon
Telerik team
Velmurugan
Top achievements
Rank 1
Share this question
or