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

Problem with RadComboBox SelectedIndexChanged events even if you do not change the control value

3 Answers 335 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
bo
Top achievements
Rank 1
bo asked on 06 Jul 2008, 09:13 PM
When i click Button1, it's just bind the data to RadGrid1,
and select export format from ExportList(RadComboBox) fire the event ExportList_SelectedIndexChanged do export.

But if i click Button1 again, the ExportList_SelectedIndexChanged fire again.
Any idea why? because it's should fire Button1_Click event.


Thanks!



Here is ASPX page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
   <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
    <br /> 
    <telerik:RadComboBox ID="ExportList" AutoPostBack="true" runat="server"  
    onselectedindexchanged="ExportList_SelectedIndexChanged"
        <Items> 
            <telerik:RadComboBoxItem Text="Export" Value="Export" runat="server"/> 
            <telerik:RadComboBoxItem Text="Export to Excel" Value="Excel" runat="server"/> 
            <telerik:RadComboBoxItem Text="Export to ExcelML" Visible="false" Value="ExcelML"  runat="server"/> 
            <telerik:RadComboBoxItem Text="Export to Word" Value="Word"  runat="server"/> 
            <telerik:RadComboBoxItem Text="Export to CSV" Value="CSV" runat="server"/> 
            <telerik:RadComboBoxItem Text="Export to PDF" Value="PDF"  runat="server"/> 
        </Items> 
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    </telerik:RadComboBox> 
     
    <br /> 
     
    <telerik:RadGrid ID="RadGrid1" GridLines="None" AllowSorting="true" runat="server"
    <MasterTableView DataKeyNames="CustomerID"
        <Columns> 
            <telerik:GridButtonColumn Text="Edit" HeaderText="Edit" CommandName="Select"
            </telerik:GridButtonColumn> 
        </Columns> 
        <ExpandCollapseColumn Visible="False"
         
        <HeaderStyle Width="19px"></HeaderStyle> 
        </ExpandCollapseColumn> 
 
        <RowIndicatorColumn Visible="True"
        <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
    </MasterTableView> 
     
    <ClientSettings> 
        <Selecting AllowRowSelect="True" /> 
    </ClientSettings> 
</telerik:RadGrid> 
    </form> 
</body> 
</html> 

Here is code behind

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
 
public partial class Default4 : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
    } 
 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        DataClassesDataContext customers = new DataClassesDataContext(); 
 
        var query = from customer in customers.Customers 
                    select new { customer.CustomerID, customer.ContactName, customer.Address, customer.City }; 
 
        RadGrid1.DataSource = query; 
        RadGrid1.DataBind(); 
    } 
 
    public void ConfigureExport(bool ExportOnlyData, bool IgnorePaging, bool OpenInNewWindow) 
    { 
        RadGrid1.ExportSettings.ExportOnlyData = ExportOnlyData; 
        RadGrid1.ExportSettings.IgnorePaging = IgnorePaging; 
        RadGrid1.ExportSettings.OpenInNewWindow = OpenInNewWindow; 
        RadGrid1.ExportSettings.FileName = "12345"
    } 
 
    public void ConfigureExport() 
    { 
        ConfigureExport(truetruetrue); 
    } 
 
    protected void ExportList_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        if (ExportList.SelectedIndex != 0) 
        { 
            switch (ExportList.SelectedValue) 
            { 
                case "Excel"
                    ConfigureExport(); 
                    RadGrid1.MasterTableView.ExportToExcel(); 
                    break
 
                case "ExcelML"
                    break
 
                case "Word"
                    ConfigureExport(); 
                    RadGrid1.MasterTableView.ExportToWord(); 
                    break
 
                case "CSV"
                    ConfigureExport(); 
                    RadGrid1.MasterTableView.ExportToCSV(); 
                    break
 
                case "PDF"
                    ConfigureExport(); 
                    RadGrid1.ExportSettings.Pdf.AllowCopy = true
                    RadGrid1.ExportSettings.Pdf.AllowModify = true
                    RadGrid1.ExportSettings.Pdf.AllowPrinting = true
                    RadGrid1.ExportSettings.Pdf.PaperSize = Telerik.Web.UI.GridPaperSize.Letter; 
                    RadGrid1.MasterTableView.ExportToPdf(); 
                    break
 
                default
                    break
            } 
        } 
    } 
 

3 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 07 Jul 2008, 05:45 AM
Hello bo,

Please, answer our questions in  Ticket ID: 148265.

Sincerely yours,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 17 Jul 2008, 04:07 PM
I too am having this problem, and I can't see the solution in that ticket.  Can it be posted here?
0
Simon
Telerik team
answered on 21 Jul 2008, 02:21 PM
Hello there,

You need to somehow catch the second time the SelectedIndexChanged event handler fires and cancel its execution. For example, this can be done by using a Session variable as shown in the code below:

protected void ExportList_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        if ((Session["gridWasExported"] != null) && 
            ((bool) Session["gridWasExported"])) 
        { 
            Session["gridWasExported"] = false
 
            return
        } 
 
        Session["gridWasExported"] = true
 
        if (ExportList.SelectedIndex != 0) 
        { 
            ... 
        } 
    } 

Since you export the Grid to some file format on the first change of the index, the content of the chosen file format is returned by the server instead of the processed page. So, the page does not 'know' that the event fired and just knows that it should fire. Therefore, when you do another postback with the Button, the event fires again.

Kind regards,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
bo
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Bob
Top achievements
Rank 1
Simon
Telerik team
Share this question
or