0

In ASP.NET project I have to load the content( TextBlock,Buttons etc) based on item selction

<asp:DropDownList ID="ddl_FieldType" CssClass="form-control" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl_FieldType_SelectedIndexChanged">
    <asp:ListItem Text="Single Line Text" Value="0"></asp:ListItem>
    <asp:ListItem Text="Multiple Line Text" Value="5"></asp:ListItem>
    <asp:ListItem Text="Date Time" Value="2"></asp:ListItem>
    <asp:ListItem Text="Date Only" Value="4"></asp:ListItem>
    <asp:ListItem Text="Single Select" Value="1"></asp:ListItem>
    <asp:ListItem Text="Multiple Select" Value="6"></asp:ListItem>
    <asp:ListItem Text="Yes / No" Value="3"></asp:ListItem>
</asp:DropDownList>

I faced error while changing item selection related to postback or callback:

enter image description here

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
jayanta
  • 165
  • 1
  • 11

1 Answers1

0

I would probably try to achieve this with javascript.

Something like this should work:

<asp:DropDownList ID="ddl_FieldType" CssClass="form-control" runat="server" Onchange=findselected()>
<asp:ListItem Text="Single Line Text" Value="0"></asp:ListItem>
<asp:ListItem Text="Multiple Line Text" Value="5"></asp:ListItem>
<asp:ListItem Text="Date Time" Value="2"></asp:ListItem>
<asp:ListItem Text="Date Only" Value="4"></asp:ListItem>
<asp:ListItem Text="Single Select" Value="1"></asp:ListItem>
<asp:ListItem Text="Multiple Select" Value="6"></asp:ListItem>
<asp:ListItem Text="Yes / No" Value="3"></asp:ListItem>

<script type="text/javascript">
            function findselected() {
                var selMenu =    document.getElementById('<%=DropDownList1.ClientID%>');
                var someField = document.getElementById('<%=TB1.ClientID%>');
                var anotherField = document.getElementById('label1');
                var btnField= document.getElementById('<%=ExportBtn.ClientID%>');
                if (selMenu.value == '2' || selMenu.value =='3') {
                    someField.style.display = "none";
                    anotherField.style.display = "none";
                    btnField.style.display = "none";
                }
                else {
                    someField.style.display = "";
                    anotherField.style.display = "";
                    btnField.style.display = "";
                }
            }
 </script>

Hope this helps, Apex

apexlol
  • 130
  • 11