Re: Adding Validator Control at runtime in a Custom Control

Discussion in 'ASP .Net' started by mudasir.ahmed@gmail.com, Dec 16, 2004.

  1. Guest

    Hi Wim,
    How do we link the TextBox to this validator control class in runtime
    ?
    Could you please tell.

    Thanks
    _
    Muds.

    Wim Hollebrandse wrote:
    > I was being rather silly. I enabled tracing and saw the whole chain

    of
    > events, but yet didn't think of moving the code into the OnInit.
    >
    > Thanks,
    > Wim
    >
    > "Daniel Cazzulino" <> wrote in message
    > news:O3ILqZwuBHA.1860@tkmsftngp04...
    > > I have a printed graph of the event sequence in my pocket, just to

    > remember
    > > always the order:
    > >
    > > OnInit
    > > -- LoadViewState
    > > ---- LoadPostData
    > > ------ OnLoad
    > > -------- RaisePostDataChangedEvent
    > > ---------- RaisePostBackEvent
    > > ------------ OnPreRender
    > > -------------- SaveViewState
    > > ---------------- Render
    > > ------------------ Dispose
    > >
    > > Daniel
    > >
    > > "Wim Hollebrandse" <wim.hollebrandseATvi.net> wrote in message
    > > news:OyVRuGwuBHA.2280@tkmsftngp05...
    > > > Fantastic Daniel. That did the trick indeed.
    > > >
    > > > Thanks!
    > > > Wim
    > > >
    > > >
    > > > "Daniel Cazzulino" <> wrote in message
    > > > news:urZDW$vuBHA.2324@tkmsftngp02...
    > > > > Try using OnInit override instead of OnPreRender.
    > > > > OnPreRender event happens after LoadViewState and LoadPostData,

    and
    > that
    > > > may
    > > > > be the problem.
    > > > > OnInit is the first event in the chain.
    > > > >
    > > > > HTH,
    > > > > Daniel
    > > > >
    > > > >
    > > > > "Wim Hollebrandse" <wim.hollebrandseATvi.net> wrote in message
    > > > > news:utRxFxfuBHA.1608@tkmsftngp04...
    > > > > > Hi,
    > > > > >
    > > > > > I have a class which inherits from the TextBox class and I am

    > creating
    > > a
    > > > > > requiredfield validator for this input control at runtime.

    Client
    > side
    > > > > > validation seems to work fine, but when I force server side

    > > validation,
    > > > > > nothing happens, it simply posts the form and doesn't display

    the
    > > error
    > > > > > message. I think this might have to do with Viewstate stuff,

    and
    > also,
    > > > the
    > > > > > fact that it creates the new control all over again (in the

    class
    > > def.),
    > > > > > when the form is being submitted.
    > > > > >
    > > > > > Any ideas?
    > > > > >
    > > > > > Here's a simplified example (the control class definition) of

    what I
    > > am
    > > > > > trying to do:
    > > > > >
    > > > > > // --- Required Field Textbox
    > > > > > public class Required : TextBox
    > > > > > {
    > > > > > protected RequiredFieldValidator reqCtl;
    > > > > > public string InvalidMessage;
    > > > > >
    > > > > > protected override void OnPreRender(System.EventArgs e) {
    > > > > > reqCtl = new RequiredFieldValidator();
    > > > > > reqCtl.ControlToValidate = this.ID;
    > > > > > reqCtl.ErrorMessage = this.InvalidMessage;
    > > > > > //reqCtl.EnableClientScript = false;
    > > > > > //this.Parent.Controls.Add(reqCtl);
    > > > > > Controls.Add(reqCtl);
    > > > > > }
    > > > > >
    > > > > > protected override void Render(HtmlTextWriter w)
    > > > > > {
    > > > > > base.Render(w);
    > > > > > reqCtl.RenderControl(w);
    > > > > > }
    > > > > > }
    > > > > > //--
    > > > > >
    > > > > > Any ideas of how to get server side validation to work in

    this
    > > example,
    > > > > are
    > > > > > welcome.
    > > > > >
    > > > > > Thanks!
    > > > > > Wim
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >
     
    , Dec 16, 2004
    #1
    1. Advertising

  2. Dim aspPage As New String("<asp:CompareValidator Type="Currency"
    Operator="DataTypeCheck" ErrorMessage="Please use a Currency value"
    runat="server" ControlToValidate="Text_Box_Test" />")
    Dim aspControls As New Control
    aspControls = Page.ParseControl(aspPage)
    Page.Controls.Add(aspControls)

    Where Text_Box_Test is the ID of control to validate.

    I hope this code helps you.

    Atte. Elmer Carías
    El Salvador


    <> wrote in message
    news:...

    > Hi Wim,
    > How do we link the TextBox to this validator control class in runtime
    > ?
    > Could you please tell.
    >
    > Thanks
    > _
    > Muds.
    >
    > Wim Hollebrandse wrote:
    > > I was being rather silly. I enabled tracing and saw the whole chain

    > of
    > > events, but yet didn't think of moving the code into the OnInit.
    > >
    > > Thanks,
    > > Wim
    > >
    > > "Daniel Cazzulino" <> wrote in message
    > > news:O3ILqZwuBHA.1860@tkmsftngp04...
    > > > I have a printed graph of the event sequence in my pocket, just to

    > > remember
    > > > always the order:
    > > >
    > > > OnInit
    > > > -- LoadViewState
    > > > ---- LoadPostData
    > > > ------ OnLoad
    > > > -------- RaisePostDataChangedEvent
    > > > ---------- RaisePostBackEvent
    > > > ------------ OnPreRender
    > > > -------------- SaveViewState
    > > > ---------------- Render
    > > > ------------------ Dispose
    > > >
    > > > Daniel
    > > >
    > > > "Wim Hollebrandse" <wim.hollebrandseATvi.net> wrote in message
    > > > news:OyVRuGwuBHA.2280@tkmsftngp05...
    > > > > Fantastic Daniel. That did the trick indeed.
    > > > >
    > > > > Thanks!
    > > > > Wim
    > > > >
    > > > >
    > > > > "Daniel Cazzulino" <> wrote in message
    > > > > news:urZDW$vuBHA.2324@tkmsftngp02...
    > > > > > Try using OnInit override instead of OnPreRender.
    > > > > > OnPreRender event happens after LoadViewState and LoadPostData,

    > and
    > > that
    > > > > may
    > > > > > be the problem.
    > > > > > OnInit is the first event in the chain.
    > > > > >
    > > > > > HTH,
    > > > > > Daniel
    > > > > >
    > > > > >
    > > > > > "Wim Hollebrandse" <wim.hollebrandseATvi.net> wrote in message
    > > > > > news:utRxFxfuBHA.1608@tkmsftngp04...
    > > > > > > Hi,
    > > > > > >
    > > > > > > I have a class which inherits from the TextBox class and I am

    > > creating
    > > > a
    > > > > > > requiredfield validator for this input control at runtime.

    > Client
    > > side
    > > > > > > validation seems to work fine, but when I force server side
    > > > validation,
    > > > > > > nothing happens, it simply posts the form and doesn't display

    > the
    > > > error
    > > > > > > message. I think this might have to do with Viewstate stuff,

    > and
    > > also,
    > > > > the
    > > > > > > fact that it creates the new control all over again (in the

    > class
    > > > def.),
    > > > > > > when the form is being submitted.
    > > > > > >
    > > > > > > Any ideas?
    > > > > > >
    > > > > > > Here's a simplified example (the control class definition) of

    > what I
    > > > am
    > > > > > > trying to do:
    > > > > > >
    > > > > > > // --- Required Field Textbox
    > > > > > > public class Required : TextBox
    > > > > > > {
    > > > > > > protected RequiredFieldValidator reqCtl;
    > > > > > > public string InvalidMessage;
    > > > > > >
    > > > > > > protected override void OnPreRender(System.EventArgs e) {
    > > > > > > reqCtl = new RequiredFieldValidator();
    > > > > > > reqCtl.ControlToValidate = this.ID;
    > > > > > > reqCtl.ErrorMessage = this.InvalidMessage;
    > > > > > > //reqCtl.EnableClientScript = false;
    > > > > > > //this.Parent.Controls.Add(reqCtl);
    > > > > > > Controls.Add(reqCtl);
    > > > > > > }
    > > > > > >
    > > > > > > protected override void Render(HtmlTextWriter w)
    > > > > > > {
    > > > > > > base.Render(w);
    > > > > > > reqCtl.RenderControl(w);
    > > > > > > }
    > > > > > > }
    > > > > > > //--
    > > > > > >
    > > > > > > Any ideas of how to get server side validation to work in

    > this
    > > > example,
    > > > > > are
    > > > > > > welcome.
    > > > > > >
    > > > > > > Thanks!
    > > > > > > Wim
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    >
     
    Elmer Carías, Dec 17, 2004
    #2
    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. Replies:
    4
    Views:
    905
    Richter~9.6
    Feb 13, 2007
  2. Ron Strong

    Adding validator to simple server control

    Ron Strong, Dec 26, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    123
    John Saunders
    Dec 28, 2004
  3. Mark Siffer

    adding validator control to editable data grid at runtime

    Mark Siffer, Jun 21, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    205
    Mark Siffer
    Jun 21, 2004
  4. Zoe Hart
    Replies:
    1
    Views:
    373
    Scott Wisniewski
    Jan 8, 2004
  5. Scott Yenor

    How to get custom control to work with custom validator

    Scott Yenor, Jan 27, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    213
    Scott Yenor
    Jan 27, 2004
Loading...

Share This Page