0
I just started working with WebForms and it became a question, due to always messing with the asp.net mvc.
Supposing I have one DropDownList and populated the DataSource of it with various records, when held the PostBack i can’t recover the data that is in that DropDownList, have any way to recover these data? what is the best way to work with the data in PostBack . Thank you.
    private void PopularEmpresasDoGrupoDoUsuario()
    {
        VOB2BUser voUser = GetSessionUser();
        DAOB2BCompany daoCompany = new DAOB2BCompany(((Page)Page).DATABASE);
        DAOB2BUser daoUser = new DAOB2BUser(((Page)Page).DATABASE);
        DAOB2BCompanyGroupUser daoCompanyGroupUser = new DAOB2BCompanyGroupUser(((Page)Page).DATABASE);
        var userGroup = daoCompanyGroupUser.GetUserGroup(voUser.IdUser);
        if (userGroup == null)
        {
            divEmpresasDoGrupoDoUsuario.Visible = false;
        }
        else
        {
            divEmpresasDoGrupoDoUsuario.Visible = true;
            dropDownListEmpresasDoGrupoDoUsuario.DataSource = daoCompany.GetEmpresasVinculadasNoGrupoDeEmpresa(userGroup.IdGroup);
            dropDownListEmpresasDoGrupoDoUsuario.DataBind();
            upEmpresasDoGrupoDoUsuario.Update();
            dropDownListEmpresasDoGrupoDoUsuario.SelectedIndex = 0;
            dropDownListEmpresasDoGrupoDoUsuario_SelectedIndexChanged(dropDownListEmpresasDoGrupoDoUsuario, new EventArgs());
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {                
            if (Session["USER"] != null)
            {                    
                PopularEmpresasDoGrupoDoUsuario();
                SetUserPermissions(fc);
            }
        }            
    }
						
you want, when selecting the item in the dropdown, it performs the postback and you take the value that was selected ?
– Rovann Linhalis
@Rovannlinhalis, no friend, I want to know how I work with all the data that was uploaded in this Dropdownlist, let’s assume, when performing the postback, I take everything that’s on its datasource and work with those records, you know? I only see one way to work with that, playing in a Viewstate, but I know it’s not good practice, I wonder if there’s any other way to do it!
– Nicola Bogar
and, the postback can be fired in several different ways, some specific control for you to treat it ? or it would be in all postbacks that occur on the page ?
– Rovann Linhalis
@Rovannlinhalis, I am developing a routine that I will need to take all postback of the page the data and perform a filter on it to find the record I need, IE, I will take this data in all postbacks.
– Nicola Bogar