Getting PostBack Data from DropDownList Control

L

Lance

Hi Guys.

Im trying to catch the postback event for a control that
Inherits from the System.Web.UI.Webcontrols.DropDownList

Ive used the code below for controls inherited from
System.Web.UI.Controls
But it dosnt work when I inherit from dropdownlist.

Any ideas?


Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Collections.Specialized

Public Class SlaveDDL
Inherits System.Web.UI.Control
Implements IPostBackDataHandler

Public Overridable Function LoadPostData(ByVal
postDataKey As String, ByVal values As
NameValueCollection) As Boolean Implements
IPostBackDataHandler.LoadPostData
Dim str As String = "Load the posted data"
Return True
End Function


Public Overridable Sub RaisePostDataChangedEvent()
Implements IPostBackDataHandler.RaisePostDataChangedEvent
End Sub
End Class
 
V

Victor Garcia Aprea [MVP]

Hi Lance,

There is nothing special besides implementing IPostBackDataHandler.
Are you dynamically creating your DropDownList-derived control and adding it
to the Controls collection? If so, at which point?
Is your DropDownList-derived control a child of a composite control? If so,
it the composite implementing INamingContainer marker interface?

If this doesn't help please post a small code snippet that repros your
issue,

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
 
L

Lance

Hi Victor

Thanks for your reply,

The problem I am having is that when I implement the
iPostBackDataHandler.
First I found I had to shadow it in VB which you dont have
to do in C# apparently.

Even after I did this the RaisePostDataChangedEvent or
LoadPostData functions dont fire.

Here is the most basic example I could come up with....

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections.Specialized

Public Class TestDropDown
Inherits System.Web.UI.WebControls.DropDownList
Implements IPostBackDataHandler

Protected Overrides Sub AddAttributesToRender(ByVal
writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)
writer.AddAttribute("onClick", "doHello()")
End Sub

Protected Overrides Sub Render(ByVal output As
HtmlTextWriter)
Dim s As String = ControlChars.CrLf & "<script
language=JavaScript>"
s = s & ControlChars.CrLf
s = s & "function doHello() {"
s = s & ControlChars.CrLf
s = s & " alert(""Hello World"");"
s = s & ControlChars.CrLf
s = s & "}"
s = s & ControlChars.CrLf
s = s & "</script>"
s = s & ControlChars.CrLf
output.Write(s)
' draw our control
MyBase.Render(output)
End Sub

Public Sub RaisePostDataChangedEvent() Implements
IPostBackDataHandler.RaisePostDataChangedEvent
Dim str As String
str = "Did it Fire"
End Sub

Public Function LoadPostData(ByVal postDataKey As
String, ByVal pstcollection As NameValueCollection) As
Boolean Implements IPostBackDataHandler.LoadPostData
Dim str As String
str = "Did it Fire"
Return True
End Function

'This is required to re implement the
IPostbackDataHandler Interface
Public Shadows Interface IPostBackDataHandler
Sub RaisePostDataChangedEvent()
Function LoadPostData(ByVal postDataKey As String,
ByVal pstcollection As NameValueCollection) As Boolean
End Interface

End Class

I have searched high and low on the net for an example of
someone doing this but it looks like everyone authoring
controlls is using C#.

thanx again
Lance
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top