Implementing postback functionality in custom control

Discussion in 'ASP .Net Building Controls' started by Showjumper, Mar 5, 2005.

  1. Showjumper

    Showjumper Guest

    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...
    Showjumper, Mar 5, 2005
    #1
    1. Advertising

  2. Showjumper

    Showjumper Guest

    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
    Showjumper, Mar 6, 2005
    #2
    1. Advertising

  3. Showjumper

    Wilco Bauwer Guest

    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.

    ----
    - Wilco Bauwer
    Blog & Custom Controls @ http://wilcoding.xs4all.nl
    Wilco Bauwer, Mar 6, 2005
    #3
  4. Showjumper

    Showjumper Guest

    > 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
    Showjumper, Mar 6, 2005
    #4
  5. Showjumper

    Wilco Bauwer Guest

    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...

    ----
    - Wilco Bauwer
    Blog & Custom Controls @ http://wilcoding.xs4all.nl
    Wilco Bauwer, Mar 6, 2005
    #5
  6. Showjumper

    Showjumper Guest

    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.
    "Wilco Bauwer" <> wrote in message
    news:...
    > 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...
    >
    > ----
    > - Wilco Bauwer
    > Blog & Custom Controls @ http://wilcoding.xs4all.nl
    >
    Showjumper, Mar 6, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VmVyYQ==?=
    Replies:
    4
    Views:
    2,540
    Mark Fitzpatrick
    Oct 22, 2006
  2. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  3. Andrew Dawson

    Implementing IPostBackDataHandler in a custom web control with VB.NET

    Andrew Dawson, Aug 9, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    403
    Teemu Keiski
    Aug 12, 2004
  4. Sundararajan

    Implementing columns collection in Data grid custom control

    Sundararajan, Mar 25, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    123
    AlanM
    Mar 29, 2005
  5. Patrick Ruzand
    Replies:
    5
    Views:
    260
    Patrick Ruzand
    Mar 15, 2007
Loading...

Share This Page