开发者

Various asp controls in a ASP.NET page

开发者 https://www.devze.com 2022-12-31 11:55 出处:网络
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

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 C开发者_如何学GoontrolLente 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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消