Chris J. Frattinger
1/14/2003 5:56:00 PM
Hi,
I've been reading up on this issue, but haven't found the right answers
yet.
I created a dropdownlistbox in my .ascx page. I dragged the ascx page onto
my aspx page and I bind the dropdownlistbox to a dataset from the page_load
event on my ascx page. That works fine ( I'll use a datareader later for
efficiency).
When I make a selection change on the dropdownlistbox the postback is
triggered for my aspx page, yet the dropdownlistbox is reset back to the
original value as though it has been reloaded. EnableViewState is set to
true for the contol.
I want the control's selectedindexchanged event to fire so that I can
ultimately capture in in my aspx page by calling the raisebubbleevent( )
from the control's selectedindexchanged event. This won't happen.
I declared an object in my aspx page WithEvents using the name of the
control's ID after I inserted the control onto my aspx page as documented,
but I still can not capture the contol's selectedindexchanged event.
Here is my code in the ascx page
Public MustInherit Class WebUserControlddlbCycleShared
Inherits System.Web.UI.UserControl
Protected WithEvents orConnect As System.Data.OracleClient.OracleConnection
Protected WithEvents orCommand As System.Data.OracleClient.OracleCommand
Protected WithEvents orAdapter As System.Data.OracleClient.OracleDataAdapter
Protected WithEvents ddlbCycleShared As
System.Web.UI.WebControls.DropDownList
Protected WithEvents dsData As System.Data.DataSet
<#Region Code Removed>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'Get Database ConnectionString and connect
orConnect.ConnectionString =
ConfigurationSettings.AppSettings("ConnectString")
orConnect.Open()
'Load Billing Cycle for User
orCommand.Connection = orConnect
orCommand.CommandText = "SELECT DISTINCT BILLING_CYCLE, DESCRIPTION " & _
"FROM tablex WHERE UPPER(Trim(BILLING_CYCLE)) != 'XXX " & _
"ORDER BY BILLING_CYCLE Desc"
orAdapter.SelectCommand = orCommand
orAdapter.Fill(dsData)
ddlbCycleShared.DataSource = dsData
ddlbCycleShared.DataValueField = "BILLING_CYCLE"
ddlbCycleShared.DataTextField = "DESCRIPTION"
ddlbCycleShared.DataBind()
'orConnect.Close()
End If
End Sub
Protected Sub ddlbCycleShared_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ddlbCycleShared.SelectedIndexChanged
RaiseBubbleEvent(ddlbCycleShared, e)
End Sub
End Class
Here is my capture of the bubbleevent in my aspx page:
Protected Overrides Function OnBubbleEvent(ByVal source As Object, ByVal
args As System.EventArgs) As Boolean
If source.GetType.Equals(GetType(DropDownList)) Then
Dim objDDLB As DropDownList = source
Select Case objDDLB.ID
Case "ddlbCycleShared"
'Determine which event bubbled up
Return True
End Select
End If
End Function
TIA,
Chris