Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Re: Adding Validator Control at runtime in a Custom Control (http://www.velocityreviews.com/forums/t92898-re-adding-validator-control-at-runtime-in-a-custom-control.html)

mudasir.ahmed@gmail.com 12-16-2004 05:57 PM

Re: Adding Validator Control at runtime in a Custom Control
 
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" <d_kazzu@yahoo.com> 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" <d_kazzu@yahoo.com> 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 12-17-2004 09:14 PM

Re: Adding Validator Control at runtime in a Custom Control
 
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
elmer_carias@hotmail.com

<mudasir.ahmed@gmail.com> wrote in message
news:1103219827.962314.29030@z14g2000cwz.googlegro 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" <d_kazzu@yahoo.com> 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" <d_kazzu@yahoo.com> 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
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

>





All times are GMT. The time now is 07:28 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.