Implementing postback functionality in custom control

S

Showjumper

Here is my situation. I first made a custom composite control (consisting of
a textbox and button) that does a whois lookup based on the domain name
entered in the textbox. Getting the lookup sub to fire in the composite
version is not a problem b/c all i do is add AddHandler LookUp.Click,
AddressOf DoLookUp.

Now i have i attempted to make a rendered version of the control in which i
directly render the html for the textbox and button. I have been over the
documentation for the IPostBackDataHandler, IPostBackEventHandler interfaces
and their associated functions. I have also consulted my books on server
control building. All the examples i have seen show how to add postback
functionality to simple controls, i.e a custom button control for instance
which then has its event called from the codebehing of the aspx page. What i
want to do is add postback functioality to the control and then with that
call the dolookup sub. Can someone walk me thru? I can post code if needed.
Or if my explanation is not clear enoughi can explain further. How do i
trigger the sub in the custom control from the rendered button? I am using
vbnet BTW. The more detailed explanation the better since i have banging my
head against the wall for sometime (not literally tho'). Any and all help is
appreciated...
 
S

Showjumper

I think i actually got it. What i did was move the lookup code to the
raisepostbackevent such that
If eventArgument = "DoLookup" Then
'do the lookup
end if

And for the submit button
wr.AddAttribute("onclick", Page.GetPostBackEventReference(Me, "DoLookup"))

Can some one comment on doing this way? Is this right? Thx...

Ashok
 
W

Wilco Bauwer

Read http://wilcoding.xs4all.nl/Wilco/View.aspx?NewsID=144 instead. You
can also take a look at the source code of some of the web controls on
my website.

The way you get a postback event reference looks ok, but you should
also register your control as a control which handles postbacks, and
implement the correct interface for handling postbacks.
 
S

Showjumper

The way you get a postback event reference looks ok, but you should also
register your control as a control which handles postbacks, and implement
the correct interface for handling postbacks.

By this i assume you mean implementing IPostBackDataHandler,
IPostBackEventHandler. If that is the case i have done so. What i have is
this and the submit button with the onclick attribute and eventargument that
mentioned previously. Can you comment or someone else can? text is the
domain name entered into the textbox and this value is maintained across
postbacks and the lookup code fires. I just want to be sure i am doing this
right. I dont htink i need to do anything in raisepostdatachanged since the
textbox value doesnt change across postbacks. Thx Ashok

Public Function LoadPostData(ByVal PostDataKey As String, ByVal Values As
NameValueCollection) As Boolean _
Implements IPostBackDataHandler.LoadPostData
text = Values(Me.UniqueID)
Return True
End Function

Public Sub RaisePostDataChangedEvent() _
Implements IPostBackDataHandler.RaisePostDataChangedEvent
' Dont need to do anything here
End Sub


Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements
System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
If eventArgument = "DoLookup" Then
'Do the lookup = lookup code fires
End If
End Sub
 
W

Wilco Bauwer

Sorry, I did not read your initial posting and assumed several things.

The way you are doing it looks about right. However, I would raise an
event, instead of handling the "event" yourself. You probably want to
handle that event outside your class (e.g. let the client of your
control do the stuff), unless it really is part of your control's
functionality...
 
S

Showjumper

Appreciate your input. I think for now i will leave it the way it is for
now since the lookup is the crux of the control.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top