Quantcast
Channel: AuthorCode » ListBox control
Viewing all articles
Browse latest Browse all 9

AutoPostBack property of ListBox in asp.net

$
0
0

If we set AutoPostBack property of the ListBox to True, then form containing Listbox is submitted automatically whenever a new item is selected.
Note: AutoPostback property uses client side javascript , if a browser does not support javaScript or if JavaScript is disabled on the browser, then this property does not work.

Example

The following example illustrate the effect of Autopostback proerty Of ListBox, suppose we have a ListBox control with AutoPostback (True) property and when a new item is selected, the SelectedIndexChanges event is raised that is associated with event ListBox_SelectedindexChanged, so whenever a new item is selected in ListBox, the form is submitted and the ListBox_SelectedIndexChanged subroutine is executed.

  1. <script runat="server">
  2.     Sub ListBox_SelectedindexChanged()
  3.         MsgBox("Index is changed")
  4.     End Sub
  5.     </script>
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head id="Head1" runat="server">
  8.     <title>AutoPostBack property of ListBox</title>
  9. </head>
  10. <body style="height: 410px; width: 768px">
  11.     <form runat="server">
  12.     <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListBox_SelectedindexChanged">
  13.     <asp:ListItem Text="USA" Value="1" />
  14.     <asp:ListItem Text="India" Value="2" />
  15.     <asp:ListItem Text="Japan" Value="3" />
  16.     </asp:ListBox>
  17.    </form>
  18. </body>
  19. </html>

Viewing all articles
Browse latest Browse all 9

Trending Articles