Adding Validation via OnItemDataBound event (ASP.NET 2.0)

R

rmccinc

OK, I am running into some issues that I cant figure out a work-around.
I am not going to post code cause I figured out WHY my issue is
happening:

-I have a datagrid, and a button that fires a click event.

-The Datagrids onitemdatabound event dynamically creates validation
controls per values from other columns in the datagrid, one of those
controls is a textbox and it is the ControlToValidate of the validation
control.

ie - Basically, think of a shopping cart with a quantity textbox and
another NOT visible column for inventory. During onitemdatabound I
check the inventory (tempInventory = e.Item.Cells(1).Text) and create
the necessary validation for Qty.

Everything works great with client side validation, the problem starts
when I attempt to process validation server side.

When my button with the click event is fired, Page.IsValid is always
true. BUT, when I move the validation control creation to the
OnItemCreated event, it all works fine.

My problem is that the validation relies on data, which OnItemDataBound
has not fired yet for that item.

Any ideas? In theory, I am thinking of creating the validation fully at
itemCreated, then disable and change validator properties at the
itemdatabound event if applicable???? I don't know if that will even
work.
 
B

Brock Allen

I can't follow exactly what's going on in your app, but as with any server
controls that are dynamically created, you need to recreate them upon postback.
I suspect that's why it's working if you do it in ItemDataBound but not when
you remove it from that event.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top