473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1497
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.