472,984 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 software developers and data experts.

Adding Validation via OnItemDataBound event (ASP.NET 2.0)

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.

Nov 19 '05 #1
1 1478
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.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ItNerd | last post by:
The following code causes two letters to be highlighted at once, so for example, if you click on Division 2 letter 'A', the letter 'A' in Division 1 is also highlighted. I want only one letter...
4
by: Anders | last post by:
Hi, I was wondering what is most efficient of the two. Is it more efficient to add server controls within the Itemtemplate and use OnItemDataBound to manipulate and databind the servercontrols. ...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
1
by: Shilpa | last post by:
Hi , I am shilpa. I have one grid. I am adding data to teh grid thorugh xml. Now i have to create a hyperlink colums when i add data to the grid depending on the value selected in another drop...
2
by: jason | last post by:
i'm trying to set the commandargument property of a buttoncolumn in the DataGrid ItemBind event. it works fine in one instance, but in the latest page i've written it doesn't seem to work, and i...
2
by: Girish | last post by:
Hello all, Im wondering why my OnItemDataBound gets fired twice here. I got this sample code from somewhere online.. and when I put a break point in the method... it hits the method twice for...
1
by: Mikeon | last post by:
Hello! I have a problem customizing the databound controls using the OnItemDataBound event. The code below is an example of what I'm trying to do. I have a datasource and basing on the data I...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
2
by: RN1 | last post by:
Consider the following code: ------------------------------ <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then 'binding data from...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.