Custom Server Control Does Not Cause Validation

G

Guest

I have a custom server control that renders a Submit button.

The button renders just fine at design and run time.
The button click event is being trapped normally.

My problem : If I add a textbox and a required field validator, my button does not cause either the normal client or server side validation to occur.

Is there a method I must call or an interface I must implement to get my custom control wired up on the Page like a normal Button control. A normal button gets the OnClick Javascript added automatically when rendered if a validation control is no the page. In addition a normal Button control causes the Page.Validate method to run.

Thank you so much for your help,

Karl
 
P

Peter Blum

In your rendered HTML for the button, create an onclick attribute with the
text from the Page.GetPostBackEventReference. The only concern is that this
method may need to be called during the OnPreRender phase. Its probably too
late to call it in Render. If you are using Render to create the button's
HTML, call GetPostBackEventReference in OnPreRender and save the string in a
field until Render.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

KarlCharlotteNc said:
I have a custom server control that renders a Submit button.

The button renders just fine at design and run time.
The button click event is being trapped normally.

My problem : If I add a textbox and a required field validator, my button
does not cause either the normal client or server side validation to occur.
Is there a method I must call or an interface I must implement to get my
custom control wired up on the Page like a normal Button control. A normal
button gets the OnClick Javascript added automatically when rendered if a
validation control is no the page. In addition a normal Button control
causes the Page.Validate method to run.
 
B

bruce barker

because you are rendering the html, you have to add the javascript call
yourself.

-- bruce (sqlwork.com)


KarlCharlotteNc said:
I have a custom server control that renders a Submit button.

The button renders just fine at design and run time.
The button click event is being trapped normally.

My problem : If I add a textbox and a required field validator, my button
does not cause either the normal client or server side validation to occur.
Is there a method I must call or an interface I must implement to get my
custom control wired up on the Page like a normal Button control. A normal
button gets the OnClick Javascript added automatically when rendered if a
validation control is no the page. In addition a normal Button control
causes the Page.Validate method to run.
 

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

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top