views:

44

answers:

2

Hello.

I am creating a products page, where the user selects an option in a radiobuttonlist for example, and then a control with the various options of that product appears in a placeholder or in a div when on of the radiobuttons is selected.

At the moment this is the code:

aspx:

<form runat="server">
<asp:CheckBoxList ID="Lentes" runat="server" OnClick="EscolheLentes">
    <asp:ListItem Value="LU">
    Lentes Unifocais
    </asp:ListItem>
    <asp:ListItem Value="LP">
    Lentes Progressivas
    </asp:ListItem>
</asp:CheckBoxList>
<asp:PlaceHolder runat="server" ID="PHLentes"></asp:PlaceHolder>
</form>

aspx.vb:

Protected Sub EscolheLentes()
        Dim ControlLente As Control
        If (Me.Lentes.Items.FindByValue("LU").Selected) Then
            ControlLente = LoadControl("LentesUnifocais.ascx")
        ElseIf (Me.Lentes.Items.FindByValue("LP").Selected) Then
            ControlLente = LoadControl("LentesProgressivas.ascx")
        End If
        Me.PHLentes.Controls.Add(ControlLente)
    End Sub

Need to use some ajax to load the control right? Am i going in the right direction?

Thanks.

+1  A: 

Have you tried adding AutoPostBack="true" and Visible="true" on your control?

hamlin11
Thanks for your help.
Filipe Costa
+1  A: 

There are several ways to achieve that:

  • True ASP.Net Web forms: Do postbacks with AutoPostback and play with the visibility of the other controls
  • Javascript: Load all the data possibly displayed with the page and handle the conditional display with javascript. This is only reasonable if the amount of data to display on one page is somewhat limited. You may want to look into JQuery or something similar if you go that way.
  • Ajax: load asynchronously only the bits you need. You may use the MSAjax framework, or Jquery (or similar) to do the client side code.

The first option is probably the fastest one to implement.

marapet
Thank you. The first option works like i want. :)
Filipe Costa