ComboBOX which best method: OnSelectedIndexChanged via autopostback or Jquery?

0

I have the following DropDownList in ASP.NET Webform

<asp:DropDownList ID="DDL_Categoria" runat="server" CssClass="form-control" AppendDataBoundItems="true" >
<asp:ListItem Value="" Selected="True">Selecione</asp:ListItem>
</asp:DropDownList>

When selecting this field, another DropDownList should automatically be completed in the form footer. What better method? Faster, politically correct?

Method 01

Code Behind + autopostback

<asp:DropDownList ... OnSelectedIndexChanged="DDL_Categoria_SelectedIndexChanged" AutoPostBack="True"

and in the code-behind I make the logic. Disadvantage: Does it load the page, if it is typing in another field can cause some delay?

Method 02:

Javascript calling in iframe. Would create a new .aspx page to receive this value

<asp:DropDownList ... onchange="nome_functionJS(this.value)"
    <script>
    function nome_functionJS(valor){
document.getElementById("IFRAMEID").src ='monta_DDL.aspx?value=' + valor
}

Method 03: Jquery (I have no idea how to call it)

    
asked by anonymous 23.05.2014 / 22:04

1 answer

3

Solution using UpdatePanel

Using UpdatePanel allows easier application maintenance by avoiding the use of javascript.

In addition, for the typing problem, simply put individual UpdatePanels on each dropdownlist and control their autoloading without interfering with the rest of the page.

One drawback is that it makes a request with all page information, even though it is not necessary. However, updating the table is done only on the updated UpdatePanels. For small to medium-sized pages this is not a problem.

Working with ASP.NET I think this is the best solution because it is already integrated with the framework, it is difficult to find cases where there are really performance problems.

The following is a good tutorial on how to work with UpdatePanel: link

Solution using jquery / ajax

For developers who use this technology routinely, it is probably easier to work with javascript than to understand the entire runtime mechanism of UpdatePanel. The big problem is to understand how dropdownlists work together with javascript. You should be very careful to interact with the right elements of the component via javascript.

One suggestion is to treat the controls as HTML elements so that your manipulation via javascript is easy. If you need to access them in code-behind, put im Id in those HTML components along with the runat="server" tag. Hence, it is possible to retrieve them in the code-behind via FindControl("IdDoContolador"); method.

    
13.07.2014 / 00:30