ayasha
ayasha

Reputation: 1251

ASP.NET DevExpress - How to get selected value of ASPxComboBox in another function

I have a ASPxUploadControl item (with an integrated Upload Button) and then a ASPxComboBox like thisenter image description here

In the first one I need to browse and select an item (picture), then I have to select an application in the second item and finally I need to upload it (click the button below). So I did this for the client side:

<dx:ASPxUploadControl ID="ASPxUploadControl_Browse" runat="server" ShowUploadButton="True" AddUploadButtonsHorizontalPosition="Left"
                UploadMode="Auto" OnFileUploadComplete="UploadControl_FileUploadComplete" AllowedFileExtensions=".jpg,.jpeg,.gif,.png" Width="280px">
                <BrowseButton Text="Sfoglia" />
                <UploadButton Text="Carica"/>
</dx:ASPxUploadControl>
<dxe:ASPxComboBox ID="ASPxComboBox_Select" runat="server" DataSourceID="SqlDataSourceApplications"
                TextField="name" ValueField="applicationid" OnSelectedIndexChanged="ApplicationList_SelectedIndexChanged" Height="25px">
</dxe:ASPxComboBox>

And then for the server side:

protected void ApplicationList_SelectedIndexChanged(object sender, EventArgs e)
{
    ASPxComboBox cb = (ASPxComboBox)sender;
    ASPxGridCustomers.FilterEnabled = true;
    ASPxGridCustomers.FilterExpression = "( applicationid = " + cb.SelectedItem.Value + ")";

    ASPxButtonAll.ClientEnabled = true;
}

protected void UploadControl_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
    try
    {
        FileInfo fileinfo = new FileInfo(e.UploadedFile.FileName);
        string s = "";
        try
        {
            s = ASPxComboBox_Select.Value.ToString();
        }
        catch (Exception ex) 
        {
            throw new Exception(ex.Message);
        }
        byte[] attachmentfile = GetBytes(fileinfo.Name);
        putDocumentToDB(selectedApp, attachmentfile);
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

Since I need to put the file (in byte) in a database I need to know the application that the user chose. The problem is that I can't understand how to call it from inside the function UploadControl_FileUploadComplete. For now the string is completely empty..

Thanks!

Upvotes: 0

Views: 4333

Answers (1)

tt_emrah
tt_emrah

Reputation: 1053

it's because UploadControl_FileUploadComplete is a callback event handler, not a postback one.

as a work-around, try saving combobox selection in a session variable, like this:

protected void ApplicationList_SelectedIndexChanged(object sender, EventArgs e)
{
    ASPxComboBox cb = (ASPxComboBox)sender;
    ASPxGridCustomers.FilterEnabled = true;
    ASPxGridCustomers.FilterExpression = "( applicationid = " + cb.SelectedItem.Value + ")";

    Session["cbSelectedValue"] = cb.SelectedItem.Value;

    ASPxButtonAll.ClientEnabled = true;
}

protected void UploadControl_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
    try
    {
        FileInfo fileinfo = new FileInfo(e.UploadedFile.FileName);
        string s = "";
        try
        {
            s = Session["cbSelectedValue"].ToString();
        }
        catch (Exception ex) 
        {
            throw new Exception(ex.Message);
        }
        byte[] attachmentfile = GetBytes(fileinfo.Name);
        putDocumentToDB(selectedApp, attachmentfile);
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

// in case your combobox has a selected value on page load
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Session["cbSelectedValue"] = cb.SelectedItem.Value;
    }
}

Upvotes: 1

Related Questions