Cannot keep selected value in control?

F

Francois Soucy

Hi all!

I've begin my first webcontrol with asp.net. I've not build
everything but the first part is done except that the dropdownlist did not
keep is selected value between postback. I've reed many tutorial but no one
can explain me what's wrong with my code. Someone could give me a little
help?

Thanks,
Francois

######
Public Class RssControl
Inherits Panel
Implements INamingContainer

Protected CboRssDrop As New DropDownList
Private _DataTextField As String
Private _DataValueField As String
Private _DataSource As Object

#Region "Property"
Public Property DataTextField() As String
Get
Return Me._DataTextField
End Get
Set(ByVal Value As String)
Me._DataTextField = Value
Me.CboRssDrop.DataTextField = Value
End Set
End Property

Public Property DataValueField() As String
Get
Return Me._DataValueField
End Get
Set(ByVal Value As String)
Me._DataValueField = Value
Me.CboRssDrop.DataValueField = Value
End Set
End Property

Public Property DataSource() As Object
Get
Return Me._DataSource
End Get
Set(ByVal Value As Object)
Me._DataSource = Value
Me.CboRssDrop.DataSource = Value
End Set
End Property
#End Region

#Region "DataBind"
Public Overrides Sub DataBind()
Me.CboRssDrop.DataBind()
End Sub
#End Region

#Region "OnInit"
Protected Overrides Sub OnInit(ByVal e As EventArgs)
Me.CboRssDrop.AutoPostBack = True
Me.CboRssDrop.EnableViewState = True
MyBase.OnInit(e)
End Sub 'OnInit
#End Region

#Region "CreateChildCtl"
Protected Overrides Sub CreateChildControls()
Me.AfficherControl()
End Sub 'CreateChildControls
#End Region

#Region "AfficherCtl"
Protected Sub AfficherControl()
Me.Controls.Add(New LiteralControl("<table class=""Article""
cellSpacing=""0"" cellPadding=""0"" width=""240"" border=""0"">"))
Me.Controls.Add(New LiteralControl("<TR><TD
Class=""ArticleTitre"">"))
Me.CboRssDrop.Width = Unit.Percentage(90)
Me.Controls.Add(Me.CboRssDrop)
Me.Controls.Add(New LiteralControl("</td></TR><tr><td
class=""ArticleTexte"">###Text###</td></TR>"))
Me.Controls.Add(New LiteralControl("<TR><td
class=""ArticleSignature"">###SIGNATURE###</td></TR>"))
Me.Controls.Add(New LiteralControl("</TABLE>"))
Me.Controls.Add(New LiteralControl("<table class=""deco1""
cellSpacing=""0"" cellPadding=""0"" width=""200"" align=""center""
border=""0"">"))
Me.Controls.Add(New
LiteralControl("<TR><TD>&nbsp;</TD></TR></TABLE>"))
End Sub
#End Region
End Class
 
J

John Saunders

Francois Soucy said:
Hi all!

I've begin my first webcontrol with asp.net. I've not build
everything but the first part is done except that the dropdownlist did not
keep is selected value between postback. I've reed many tutorial but no
one can explain me what's wrong with my code. Someone could give me a
little help?

This can happen if your caller calls DataBind both on the initial request
and on PostBack.

John Saunders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top