Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Adding Validator Control at runtime in a Custom Control

Reply
Thread Tools

Re: Adding Validator Control at runtime in a Custom Control

 
 
mudasir.ahmed@gmail.com
Guest
Posts: n/a
 
      12-16-2004
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" <(E-Mail Removed)> 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" <(E-Mail Removed)> 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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >


 
Reply With Quote
 
 
 
 
Elmer Carķas
Guest
Posts: n/a
 
      12-17-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...

> 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" <(E-Mail Removed)> 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" <(E-Mail Removed)> 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
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struts Validator - creditCard validator smrimell@gmail.com Java 4 02-13-2007 08:32 PM
adding validator control to editable data grid at runtime Mark Siffer ASP .Net Datagrid Control 0 06-21-2004 04:33 PM
How to get custom control to work with custom validator Scott Yenor ASP .Net Web Controls 0 01-27-2004 12:37 AM
Adding custom client-side onClick handler with client-side validator controls Zoe Hart ASP .Net Web Controls 1 01-08-2004 10:45 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments