Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Martin #1
IPostBackDataHandler and validating a control -- the best place to do this.
Hi,
I have an asp.net page with two composite controls on it as well as a single
button in the asp.net page AND a single dropdown box on the page that has
its autopostback property set to true so that it posts back when ever the
selection is changed.
what i would like to do is when the button (in the aspx page NOT on any of
the composite controls) is clicked and causes a postback to validate both
composite controls - however i want no validation to occur if the dropdown
box causes the postback.
I have implemented IPostBackDataHandler in both controls and have verified
that they are both notified when the button in the page is clicked.
so i figured that i could validate each control in its respective
"RaisePostDataChangedEvent"
so basically i need to work out how to know exactly which element on the
page caused a postback.
I therefore have two questions.
1. Is my method of validating each composite control on a page in it's
respective "RaisePostDataChangedEvent" the correct way of achieving such a
feet or do I need to re-think my stagegy, if so any advice is welcome..
2. How do I tell exactly tell which element on a page caused a postback.
I appreciate any feedback or pointers to article of interest.
thanks in advance.
cheers
martin.
Martin Guest
-
validating datagridtextboxcolumn textbox, validating event fire twice, why?
Anyone has the same experience? I am trying to validate one of the textboxes inside a datagrid, but everytime when i click my mouse on another... -
Implementing IPostBackDataHandler in a custom web control with VB.NET
I have created a custom class with Visual Basic that inherits from the drop down list web control. In order to update the value properly, I have... -
validating a custom control in a datagrid
hi, i have a datagrid which display custom controls when user clicks edit, changing data. I am using customvalidator to validate this control. I... -
Validating a custom, composite web control
Hi I need to create a custom, composite server control which contains a text box that needs to be validated. I need to be able to add external... -
validating a control created at runtime
Hello, I have a question regarding validation of a control that I'm creating in an event handler (the control is not part of the static HTML... -
Peter Blum #2
Re: IPostBackDataHandler and validating a control -- the best place to do this.
Do not manually validate insider your custom control. Always let the page
developer identify exactly when validation occurs.
1. Buttons automatically call the Page.Validate() method for you unless
their CausesValidation property is false. This happens in their OnClick
method after Page_Load is done an before calling your Click event method.
Page.Validate() will run your validators.
2. Sometimes a button should never validate, such as a Cancel button. Again
the user takes control by setting CausesValidation to false.
3. AutoPostBack never calls Page.Validate(). If the user elects to validate
on autopostback, they add a call to Page.Validate() in their own event
handler for that post back.
4. Users can also call the Validate() method on individual validators and
check their IsValid property to see the result. If you want to support this,
I recommend adding a method to your custom control called Validate() that
fires the Validate() methods on each validator. Also include an IsValid
property which returns true if all validators are valid.
--- Peter Blum
[url]www.PeterBlum.com[/url]
Email: [email]PLBlum@PeterBlum.com[/email]
Creator of "Professional Validation And More" at
[url]http://www.peterblum.com/vam/home.aspx[/url]
"Martin" <martin_no_spam@martinz.co.nz> wrote in message
news:OYgcT%23qWFHA.132@TK2MSFTNGP14.phx.gbl...> Hi,
>
> I have an asp.net page with two composite controls on it as well as a
> single
> button in the asp.net page AND a single dropdown box on the page that has
> its autopostback property set to true so that it posts back when ever the
> selection is changed.
>
> what i would like to do is when the button (in the aspx page NOT on any of
> the composite controls) is clicked and causes a postback to validate both
> composite controls - however i want no validation to occur if the dropdown
> box causes the postback.
>
> I have implemented IPostBackDataHandler in both controls and have verified
> that they are both notified when the button in the page is clicked.
> so i figured that i could validate each control in its respective
> "RaisePostDataChangedEvent"
>
> so basically i need to work out how to know exactly which element on the
> page caused a postback.
>
> I therefore have two questions.
>
> 1. Is my method of validating each composite control on a page in it's
> respective "RaisePostDataChangedEvent" the correct way of achieving such a
> feet or do I need to re-think my stagegy, if so any advice is welcome..
>
> 2. How do I tell exactly tell which element on a page caused a postback.
>
> I appreciate any feedback or pointers to article of interest.
>
> thanks in advance.
>
> cheers
>
> martin.
>
>
Peter Blum Guest
-
Martin #3
Re: IPostBackDataHandler and validating a control -- the best place to do this.
Hi Peter,
Thanks for all of the information, i found it really usefull.
I have one additional question about your forth option
this,> 4. Users can also call the Validate() method on individual validators and
> check their IsValid property to see the result. If you want to supportOk, so I add a method called validate to my custom control, but how can I> I recommend adding a method to your custom control called Validate() that
> fires the Validate() methods on each validator. Also include an IsValid
> property which returns true if all validators are valid.
ensure that this gets fired.
for example the "Validate()" method of an asp page gets fired after
page_load has run on postback but before any button click where the button
has it causesvalidation property set to true.
How can i implement this behaviour in a composite server controls??
can you offer any advice??
cheers
martin.
"Peter Blum" <PLBlum@Blum.info> wrote in message
news:uSgN$GxWFHA.1148@tk2msftngp13.phx.gbl...Again> Do not manually validate insider your custom control. Always let the page
> developer identify exactly when validation occurs.
> 1. Buttons automatically call the Page.Validate() method for you unless
> their CausesValidation property is false. This happens in their OnClick
> method after Page_Load is done an before calling your Click event method.
> Page.Validate() will run your validators.
>
> 2. Sometimes a button should never validate, such as a Cancel button.validate> the user takes control by setting CausesValidation to false.
>
> 3. AutoPostBack never calls Page.Validate(). If the user elects tohas> on autopostback, they add a call to Page.Validate() in their own event
> handler for that post back.
>
>
> --- Peter Blum
> [url]www.PeterBlum.com[/url]
> Email: [email]PLBlum@PeterBlum.com[/email]
> Creator of "Professional Validation And More" at
> [url]http://www.peterblum.com/vam/home.aspx[/url]
>
> "Martin" <martin_no_spam@martinz.co.nz> wrote in message
> news:OYgcT%23qWFHA.132@TK2MSFTNGP14.phx.gbl...> > Hi,
> >
> > I have an asp.net page with two composite controls on it as well as a
> > single
> > button in the asp.net page AND a single dropdown box on the page thatthe> > its autopostback property set to true so that it posts back when everof> > selection is changed.
> >
> > what i would like to do is when the button (in the aspx page NOT on anyboth> > the composite controls) is clicked and causes a postback to validatedropdown> > composite controls - however i want no validation to occur if theverified> > box causes the postback.
> >
> > I have implemented IPostBackDataHandler in both controls and havea> > that they are both notified when the button in the page is clicked.
> > so i figured that i could validate each control in its respective
> > "RaisePostDataChangedEvent"
> >
> > so basically i need to work out how to know exactly which element on the
> > page caused a postback.
> >
> > I therefore have two questions.
> >
> > 1. Is my method of validating each composite control on a page in it's
> > respective "RaisePostDataChangedEvent" the correct way of achieving such>> > feet or do I need to re-think my stagegy, if so any advice is welcome..
> >
> > 2. How do I tell exactly tell which element on a page caused a postback.
> >
> > I appreciate any feedback or pointers to article of interest.
> >
> > thanks in advance.
> >
> > cheers
> >
> > martin.
> >
> >
>
Martin Guest



Reply With Quote

