Combobox which best method: Onselectedindexchanged via autopostback or Jquery?

Asked

Viewed 595 times

0

I have the following Dropdownlist on 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, automatically another Dropdownlist must be completed in the footer of the form. What is the best method? Faster, politically correct?


Method 01

Code Behind + autopostback

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

and in code-Behind I make the logic. Disadvantage: It loads the page, if it is typing in another field may cause some delay?


Method 02:

Javascript calling in iframe. Create a new page . aspx 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 what to call)

  • With codebehind vc you can use Updatepanel with triggers to update another update panel below. With jquery, you can make the call ajax life and return a list to insert in this new combo

  • updatepanel I don’t like using is the ajax Component of webform right? I think it’s kind of archaic and I don’t know.. rs I think the best way is javascript because it doesn’t interfere with the form the faster it is codebehind, but a refresh on the screen, losing the focus of the user’s field, one day when the internet is not good can be very annoying.. so I wanted to know how the most experienced staff recommends.

  • Just the suit still from webforms may also be called arcaico and the UpdatePanel is an ajax made specifically and prepared in a useful way for Webforms

  • 1

    About losing focus after refresh via codebehind, there are several ways to solve the problem. For example, you can give a ". Focus()" in control. Or include "#+some-id-any" in the button or form action. That is, losing focus is no problem. In webform the problem is always the "blessed" refresh. I do not like refresh on the screen when changing a control. I would use ajax...

1 answer

3


Solution using Updatepanel

Using Updatepanel, allows easier maintenance of the application because it avoids the use of javascript.

Also, regarding the typing problem, just put individual Updatepanels on each dropdownlist and control the authentication of the same, without interfering with the rest of the page.

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

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

Below is shown a good tutorial on how to work with Updatepanel: http://msdn.microsoft.com/en-us/library/vstudio/system.web.ui.updatepanel(v=vs.100). aspx

Solution using jquery/ajax

For developers who routinely use this technology, it’s probably easier to work with javascript than to understand the entire Updatepanel functionality engine. The big problem is understanding how dropdownlists work together with javascript. Great care should be taken to interact with the right elements of the component via javascript.

One suggestion is: treat the controls as HTML elements so that their handling via javascript is easy. If you need to access them in code-Behind, put im Id on these HTML components along with the runat="server" tag. Hence, it is possible to recover them in code-Behind via method FindControl("IdDoContolador");.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.