Domanda

My problem is that SelectedIndexChanged of ddlObra control is not firing, but when I erase the Page.ClientScript.RegisterOnSubmitStatement of Page_Load, everything works fine. I can't understand this behavior.

Here is the code:

protected void Page_Load(object sender, EventArgs e)
{   
    if (!IsPostBack)
    {            
        CarregarDropDownLists();            
    }
    Page.ClientScript.RegisterOnSubmitStatement(Page.GetType(), "OnSubmitScript", "return handleSubmit()");
}

protected void ddlObra_SelectedIndexChanged(object sender, EventArgs e)
{
    List<Entidades.Empreendimento.Unidade> unidades = Entidades.Empreendimento.Unidade.ListaUnidades(txtLogin.Text);
    ddlBloco.Items.Clear();
    ddlUnidade.Items.Clear();
    ddlBloco.Items.Insert(0, new ListItem("----- Bloco -----", ""));
    ddlUnidade.Items.Insert(0, new ListItem("----- Unidade -----", ""));
    //if (unidades.Count == 1) return;

    foreach (Entidades.Empreendimento.Unidade Un in unidades)
    {
        if (Un.ObraVinculo.idObraCrm.ToString() == ddlObra.SelectedValue)
        {
            if (!ddlBloco.Items.Contains(new ListItem(Un.BlocoCRM.Nome, Un.BlocoCRM.CodigoCRM)))
            {
                ddlBloco.Items.Add(new ListItem(Un.BlocoCRM.Nome, Un.BlocoCRM.CodigoCRM));
            }

            Bandeira = Un.Bandeira;
            Estado = Un.Estado;
        }
    }
    ddlBloco.SelectedIndex = 0;
    ddlUnidade.SelectedIndex = 0;

    LoadAreas();
}

This code is in the .aspx file

<script type="text/javascript">
    function handleSubmit() {
        if (typeof (ValidatorOnSubmit) == 'function' && ValidatorOnSubmit() == false) {
            return false;
        } else {
            $("#btnEnviar").click(function () { return false }).fadeTo(200, 0.5);
            return true;
        }
    }
</script>

Thank you guys for your help!

È stato utile?

Soluzione

The client script executed by the submission of the form must return true in order to allow the form to submit. This enables the client-side script to prevent the submission of the form conditionally.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top