Adding Validation via OnItemDataBound event (ASP.NET 2.0)

Discussion in 'ASP .Net' started by rmccinc@hotmail.com, Sep 28, 2005.

  1. Guest

    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.
    , Sep 28, 2005
    #1
    1. Advertising

  2. Brock Allen Guest

    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.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > 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.
    >
    Brock Allen, Sep 29, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jason
    Replies:
    2
    Views:
    5,076
    jason
    Jun 14, 2005
  2. TS
    Replies:
    14
    Views:
    662
  3. Luigi
    Replies:
    0
    Views:
    450
    Luigi
    Mar 6, 2008
  4. GOKU24

    OnItemDataBound event not firing

    GOKU24, Jul 8, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    153
    GOKU24
    Jul 8, 2003
  5. Joey
    Replies:
    0
    Views:
    129
Loading...

Share This Page