473,626 Members | 3,221 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ControlToValida te 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 1513
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 ControlToValida te 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
1754
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 highlighted, and I wand the proper division number to be highlighted alone, as well. It seems that because the letters bound to the letterList datalist in a nested datalist, I cannot call the onitemdatabound event on one hyperlink only, because...
4
1818
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. Or is better to send the DataItems via. a method/function from within the Itemtemplate (<%# call function %>) Id love to hear your thoughts. Anders
2
3744
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 <asp:EditCommandColumn> I want either a textbox or dropdown to appear when I check what is being edited. I thought I could create the dropdown on the fly and add it to the datagrid as below but It's not appearing. I imagined I could populate the dropdown
1
1230
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 down. How do i do this. Please Suggest. Thanks and Regards,
2
2665
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 can't see why. can anyone tell me why this chunk of code works: <asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 136px" runat="server" CellPadding="3" OnItemDataBound="DataGridBindEvent"...
2
1996
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 each row rendered... Any insights?? Thanks! Girish
1
1150
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 want to customize the cells in the DataList for example by setting the CssClass property. Everything works fine the first time, but on PostBack the OnItemDataBound does not fire because the datasource is only bound when !IsPostBack and the...
4
4472
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 selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new row to the table, updates all of the child control Ids and sets visibility etc. The hidden...
2
1800
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 DB to the Repeater End If End Sub
0
8265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.