I have used the Ajax control toolkit ModalPopExtender object to show a ListBox (System.Web.UI.WebControls.ListBox) with a preselected item. The ListBox is located within a Table (System.Web.UI.WebControls.Table). The listbox is shown when the PopupControlID
control is activated, however although the preselected item is seen to have been selected if one scrolls down the list it is not shown highlighted at the bottom of the listbox. If I avoid using the ModalPopExtender and simply put the same ListBox (ie. Table)
directly on the page, the selected item is shown highlighted at the bottom of the ListBox (ie. last of visible list items). IDoes anyone know of a way of showing the selected item within the ListBox when using the ModalPopExtender, or is there a possibility
that this is due to an issue with the object?
The code is part of a table creation routine written as 'codebehind' and creates a listbox incorporating a series of times from which the user can select the appropriate one. The original time selections have been set previously and stored in a MySQL database,
and a ListBox array (popUpLstBxItm) is created for each table entry with the variable indxSlctd pointing to the particular item in each listbox case ...
.
.
Dim indxSlctd As Integer = 0
For i = 0 To strTmRange.Count - 1 popUpLstBxItm(i) = New System.Web.UI.WebControls.ListItem popUpLstBxItm(i).Text = strTmRange(i).ToString
If itmAppntnmtTbl(cntRow - 1, 4).Text = strTmRange(i).ToString Then indxSlctd = i End If
this ListBox is then incorporated in a TableCell (System.Web.UI.WebControls.TableCell), a TableRow (System.Web.UI.WebControls.TableRow) and finally a Table (System.Web.UI.WebControls.Table) object called popUpLstBxTbl...
When the ModalPopupExtender is not present (ie. commented out) the ListBoxes show the selected item at the very bottom of each visible set of items, whilst when it is being invoked the listboxes do not show this although you can scroll within them to find
the selected item highlighted. It may be that the scrollbar is initialised by the the ModalPopupExtender during the calls to Init or Load, but this is not clear. The problem also exists when the PopupControlExtender object is implemented in place of the ModalPopupExtender,
so this seems to be generic to the AjaxControlToolkit namespace.
and Default.aspx.vb which is the VB codebehind is ...
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lstObjct As New System.Web.UI.WebControls.ListBox Dim lstItms(49) As System.Web.UI.WebControls.ListItem Dim lstMdlPopUp As New AjaxControlToolkit.ModalPopupExtender
When running this code as is you will notice that when clicking on the 'PopUp Now' button the pre-selected item (#25) is highlighted as selected when you scroll down the listbox using the scrollbar. If you select another item (say 10) the popup window will
disappear due to the AutoPostBack setting. On clicking the 'PopUp Now' button again, the selected item is again off the list, but again can be found by scrolling.
If you remove the ModalPopupExtender object, the lstObjct object is shown when the page is loaded, but this time the pre-selected item (#25) is shown at the bottom of the list of visible items in the ListBox object.
The same issue exists with PopupControlExtender.
Perhaps you could show me how I might implement your suggestion (ie. creating the listbox code during the showing of the modalpopupextender object) with regards to this example.
I did this to make the example as simple as possible - ie. no additional buttons, etc. needed. The functionality nevertheless allows you to drag the scroll bar with the mouse and select any item by clicking on it - after which the listbox will disappear
(this is caused by the AutoPostBack set to true ofcourse). When the 'PopUp Now' button is pressed once more, the listbox reapears with the selected item not shown but highlighted (unless it is one of the first five items in the list). Dragging the scroll
bar will allow you to scroll down to the newly selected item - it is now the one that is highlighted instead of item #25 (default).
I put together the example to highlight the issue. I need the dynamic creation as each of the listboxes are shown when a client clicks on a particular table cell (each list box usually contains a different set of available times dependent on data from a
record), and the table has an unknown number of rows which depend on the database records returned by a certain query.
DrStel
0 Points
5 Posts
ListBox selection not displayed when shown by ModalPopupExtender
Jul 01, 2012 10:24 PM|LINK
I have used the Ajax control toolkit ModalPopExtender object to show a ListBox (System.Web.UI.WebControls.ListBox) with a preselected item. The ListBox is located within a Table (System.Web.UI.WebControls.Table). The listbox is shown when the PopupControlID control is activated, however although the preselected item is seen to have been selected if one scrolls down the list it is not shown highlighted at the bottom of the listbox. If I avoid using the ModalPopExtender and simply put the same ListBox (ie. Table) directly on the page, the selected item is shown highlighted at the bottom of the ListBox (ie. last of visible list items). IDoes anyone know of a way of showing the selected item within the ListBox when using the ModalPopExtender, or is there a possibility that this is due to an issue with the object?
Song-Tian - ...
All-Star
43699 Points
4304 Posts
Microsoft
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 02, 2012 08:13 AM|LINK
Hi,
Please post the related code. So I may reproduce your scenario on my side.
Feedback to us
Develop and promote your apps in Windows Store
DrStel
0 Points
5 Posts
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 02, 2012 07:34 PM|LINK
Hi...
thanks for responding to my posting so quickly.
The code is part of a table creation routine written as 'codebehind' and creates a listbox incorporating a series of times from which the user can select the appropriate one. The original time selections have been set previously and stored in a MySQL database, and a ListBox array (popUpLstBxItm) is created for each table entry with the variable indxSlctd pointing to the particular item in each listbox case ...
.
.
Dim indxSlctd As Integer = 0
For i = 0 To strTmRange.Count - 1
popUpLstBxItm(i) = New System.Web.UI.WebControls.ListItem
popUpLstBxItm(i).Text = strTmRange(i).ToString
If itmAppntnmtTbl(cntRow - 1, 4).Text = strTmRange(i).ToString Then
indxSlctd = i
End If
Next (i)
.
.
.
popUpTimeCell(cntRow - 1) = New System.Web.UI.WebControls.ListBox
AddHandler popUpTimeCell(cntRow - 1).SelectedIndexChanged, AddressOf popUpTimeCell_SelectedIndexChanged
popUpTimeCell(cntRow - 1).Items.AddRange(popUpLstBxItm)
popUpTimeCell(cntRow - 1).ID = "clndrTmSlctn_" & (cntRow - 1).ToString
popUpTimeCell(cntRow - 1).AutoPostBack = True
popUpTimeCell(cntRow - 1).SelectionMode = SelectionMode.One
popUpTimeCell(cntRow - 1).BackColor = Color.FromArgb(&HCCCCFF)
popUpTimeCell(cntRow - 1).BorderColor = Color.FromArgb(&H3366CC)
popUpTimeCell(cntRow - 1).ForeColor = Color.FromArgb(&H589393)
popUpTimeCell(cntRow - 1).BorderWidth = 1
popUpTimeCell(cntRow - 1).Height = 78
popUpTimeCell(cntRow - 1).Font.Name = "Comic Sans MS"
popUpTimeCell(cntRow - 1).Items(indxSlctd).Selected = True
.
.
.
this ListBox is then incorporated in a TableCell (System.Web.UI.WebControls.TableCell), a TableRow (System.Web.UI.WebControls.TableRow) and finally a Table (System.Web.UI.WebControls.Table) object called popUpLstBxTbl...
.
.
.
popUpLstBxTbl(cntRow - 1) = New System.Web.UI.WebControls.Table
popUpLstBxTbl(cntRow - 1).Controls.Add(popUpLstBxHdrRw(cntRow - 1))
popUpLstBxTbl(cntRow - 1).Controls.Add(popUpLstBxRw(cntRow - 1))
popUpLstBxTbl(cntRow - 1).ID = "clndrTmTbl_" & (cntRow - 1).ToString
popUpLstBxTbl(cntRow - 1).Font.Name = "Comic Sans MS"
popUpLstBxTbl(cntRow - 1).Font.Size = 12
popUpLstBxTbl(cntRow - 1).ForeColor = Color.FromArgb(&H3399)
popUpLstBxTbl(cntRow - 1).BackColor = Color.White
popUpLstBxTbl(cntRow - 1).BorderColor = Color.FromArgb(&H3366CC)
popUpLstBxTbl(cntRow - 1).BorderWidth = 1
popUpLstBxTbl(cntRow - 1).CellPadding = 1
AuthenticatedPanel.Controls.Add(popUpLstBxTbl(cntRow - 1))
.
..
.
and the table is added to the main page. Finally the ModalPopupExtender is created, again this is an array for each table entry...
.
.
.
popUpModalTbl(cntRow - 1) = New AjaxControlToolkit.ModalPopupExtender
popUpModalTbl(cntRow - 1).ID = "clndrModalTm_" & (cntRow - 1).ToString
popUpModalTbl(cntRow - 1).TargetControlID = "clndrPopUpTime_" & (cntRow - 1).ToString
popUpModalTbl(cntRow - 1).PopupControlID = "clndrTmTbl_" & (cntRow - 1).ToString
popUpModalTbl(cntRow - 1).DropShadow = True
popUpModalTbl(cntRow - 1).PopupDragHandleControlID = "clndrTmCell_" & (cntRow - 1).ToString
popUpModalTbl(cntRow - 1).CancelControlID = "clndrTmHdr_" & (cntRow - 1).ToString
AuthenticatedPanel.Controls.Add(popUpModalTbl(cntRow - 1))
.
.
.
When the ModalPopupExtender is not present (ie. commented out) the ListBoxes show the selected item at the very bottom of each visible set of items, whilst when it is being invoked the listboxes do not show this although you can scroll within them to find the selected item highlighted. It may be that the scrollbar is initialised by the the ModalPopupExtender during the calls to Init or Load, but this is not clear. The problem also exists when the PopupControlExtender object is implemented in place of the ModalPopupExtender, so this seems to be generic to the AjaxControlToolkit namespace.
Song-Tian - ...
All-Star
43699 Points
4304 Posts
Microsoft
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 03, 2012 05:29 AM|LINK
Hi,
You must use the code to create listbox when the modalpopup is shown. Please check.
Because the listbox is created dynamicly.
Feedback to us
Develop and promote your apps in Windows Store
DrStel
0 Points
5 Posts
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 04, 2012 12:00 AM|LINK
I am unsure as to what exactly you meant as regards to creating the listbox when the modalpopup is shown.
I have therefore created a simple example to illustrate the problem ...
Default.aspx is...
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
ModalPopupExtender Issue - To remove popup REM out all references to ModalPopupExtender object
<asp:Panel runat="server" ID="MainPanel">
<asp:ToolkitScriptManager ID="ToolkitScriptManager" runat="server">
</asp:ToolkitScriptManager>
<asp:Button ID="PopUpButton" runat="server" Text="PopUp Now" />
</asp:Panel>
</asp:Content>
and Default.aspx.vb which is the VB codebehind is ...
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lstObjct As New System.Web.UI.WebControls.ListBox
Dim lstItms(49) As System.Web.UI.WebControls.ListItem
Dim lstMdlPopUp As New AjaxControlToolkit.ModalPopupExtender
Dim i As New Integer
For i = 0 To 49
lstItms(i) = New System.Web.UI.WebControls.ListItem
lstItms(i).Text = "MyListItem No. " & i.ToString
Next (i)
lstObjct.Items.AddRange(lstItms)
lstObjct.AutoPostBack = True
lstObjct.ID = "lstBxID"
lstObjct.Items(25).Selected = True
MainPanel.Controls.Add(lstObjct)
lstMdlPopUp.PopupControlID = "lstBxID"
lstMdlPopUp.TargetControlID = "PopUpButton"
lstMdlPopUp.DropShadow = True
MainPanel.Controls.Add(lstMdlPopUp)
End Sub
End Class
When running this code as is you will notice that when clicking on the 'PopUp Now' button the pre-selected item (#25) is highlighted as selected when you scroll down the listbox using the scrollbar. If you select another item (say 10) the popup window will disappear due to the AutoPostBack setting. On clicking the 'PopUp Now' button again, the selected item is again off the list, but again can be found by scrolling.
If you remove the ModalPopupExtender object, the lstObjct object is shown when the page is loaded, but this time the pre-selected item (#25) is shown at the bottom of the list of visible items in the ListBox object.
The same issue exists with PopupControlExtender.
Perhaps you could show me how I might implement your suggestion (ie. creating the listbox code during the showing of the modalpopupextender object) with regards to this example.
Thanking you in advance.
Song-Tian - ...
All-Star
43699 Points
4304 Posts
Microsoft
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 04, 2012 06:47 AM|LINK
Hi,
I want to know why you set lstObjct.AutoPostBack = true ?
When the postback happen, the listbox will disappear. So the modalpop also disappear.
Feedback to us
Develop and promote your apps in Windows Store
DrStel
0 Points
5 Posts
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 04, 2012 06:48 PM|LINK
I did this to make the example as simple as possible - ie. no additional buttons, etc. needed. The functionality nevertheless allows you to drag the scroll bar with the mouse and select any item by clicking on it - after which the listbox will disappear (this is caused by the AutoPostBack set to true ofcourse). When the 'PopUp Now' button is pressed once more, the listbox reapears with the selected item not shown but highlighted (unless it is one of the first five items in the list). Dragging the scroll bar will allow you to scroll down to the newly selected item - it is now the one that is highlighted instead of item #25 (default).
Song-Tian - ...
All-Star
43699 Points
4304 Posts
Microsoft
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 05, 2012 02:21 AM|LINK
Hi,
If that, I suggesst you don't create listbox dynamicly. Any more question, pleae feel free to reply.
Feedback to us
Develop and promote your apps in Windows Store
DrStel
0 Points
5 Posts
Re: ListBox selection not displayed when shown by ModalPopupExtender
Jul 05, 2012 10:48 PM|LINK
I put together the example to highlight the issue. I need the dynamic creation as each of the listboxes are shown when a client clicks on a particular table cell (each list box usually contains a different set of available times dependent on data from a record), and the table has an unknown number of rows which depend on the database records returned by a certain query.