The IButtonControl interface and validation

Discussion in 'ASP .Net Building Controls' started by Mark, Mar 28, 2007.

  1. Mark

    Mark Guest

    Hi,

    Could some-one provide an example implementation of the CasuesValidation and
    ValidationGroup properties that one should implement when using the
    IButtonControl interface?

    I have a custom control which implements this interface and provides the
    required properties but does not fire the client-side validation.

    I have also noticed that the necessary client-side field (as would be
    rendered by using the ClientScriptManager >> RegisterForEventValidation) is
    present.
    I must be missing something obvious here.

    Regards,
     
    Mark, Mar 28, 2007
    #1
    1. Advertisements

  2. Mark

    Raj Guest

    Hi Mark,
    I have been trying to implement the IButtonControl.Click but am not
    able to make that work. I have also not been able to find and
    links/references that mght be of some help. Can you please provide some clue
    on how to implement IButtonControl. Also, if possible, please provide some
    interne references/book references that might be of use in this regard.

    Thanks!!
     
    Raj, Apr 12, 2007
    #2
    1. Advertisements

  3. Mark

    Teemu Keiski Guest

    Hi,

    with for example Button there's nothing magical in the properties itself.
    CausesValidation is just a standard server-side property utilizing
    ViewState, and so is ValidationGroup. You also need to attach the correct
    client-script to the control, just tweakinbg the properties isn't enough
    with a custom control.

    These properties are used to check a) If Button has Causesvalidation set and
    b) also the name of the ValidationGroup. First a PostBackOptions class is
    instantiated and asked it's PerformValidation and ValidationGroup properties
    are set based on settings on the Button control.

    The instance of PostBackOptions is then passed to
    Page.ClientScript.GetPostBackEventReference to get the correct client-side
    script which is appended to the rendered markup of the control (in
    AddAttributesToRender). E.g this is dealt with at render time in the
    control.

    So, what you need to do is:

    - instantiate a PostBackOptions class in your control and set its properties
    - grab the correct client script call with
    Page.ClientScript.GetPostBackEventReference (pass postbackoptions instance
    in) and render that within your control
    -Also register for event validation with
    Page.ClientScript.RegisterForEventValidation (also pass instance in)

    For more information, please see:

    http://msdn2.microsoft.com/en-us/library/system.web.ui.postbackoptions(vs.80).aspx
     
    Teemu Keiski, Apr 15, 2007
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.