473,396 Members | 1,918 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,396 software developers and data experts.

Persisting hidden fields.

Hi,

I have the following scenario:

A data-bound repeater, in which every item registers a hidden field
with the item's associated ID (a field pulled out of the database)
using the RegisterHiddenField method in the repeater's OnItemDataBound
event.

I do not re-bind the repeater on post-backs so as not to overwrite the
user input for dynamically created controls in the repeater. Which
means that the hidden fields will not be registered after the first
post back.

Ideally I wouldn't even need more than one postback - client-side
scripts verify input and the user is redirected to a new page when
clicking a button. However, should an exception be thrown at the server
side (eg database unique key violations etc), the user should be able
to correct the issue without having to capture everything again.

I wonder if there is a way to make the hidden fields persist across
post-backs (or alternatively another way to keep track of the repeater
items' associated IDs without displaying them).

I have tried the following, to no avail:
- add a HtmlInputHidden control to the page instead of using
RegisterHiddenField.
- bind the repeater in OnInit instead of Page_Load

Where does the OnItemDataBound even fit in the page's lifecycle?

Nov 10 '06 #1
2 1643
Ok I found the solution:

the hidden field must be defined in the repeater's item template,
something like this:
<input type="hidden" id="itemID" value="" runat="server/>

then in the ItemDataBound event handler, merely assign the control its
value:
DataRow row = ((DataRowView)e.Item.DataItem).Row;
HtmlInputHidden itemID = (HtmlInputHidden)e.Item.FindControl("itemID");
resolutionOptionID.Value = row["ID"].ToString();

Nov 10 '06 #2
oops, that last line should've been:

itemID .Value = row["ID"].ToString();

:)

Cheers.

Nov 10 '06 #3

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

Similar topics

4
by: Ryann | last post by:
Hello. I am creating a form that has 5 steps/pages. Each page contains about 20 fields. But I don't want to write them until they submit on the last page. I figured out that I can use hidden...
1
by: mark.reichman | last post by:
First off.. Thanks to Grant Wagner for help in a previous thread related to this one. I am at a total loss... I have multiple fields in a form with the same name. Lets call the fields with the...
2
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own...
10
by: Mark McLellan | last post by:
Dear all Following the oft-repeated advice here and ciwas I have made my site nearly 4.01 strict (working on it). There are some items on which I would appreciate your advice: 1. Hidden...
1
by: Shawn McNiven | last post by:
Hi, I've got a problem I hope someone can help me with. First some long winded explanations: I have several forms: Countries.aspx, Country.aspx, Cities.aspx and City.aspx. Countries displays a...
5
by: Roshawn Dawson | last post by:
Hi, Are hidden fields passed in the querystring when a form is posted back? If they are, must the hidden fields be server controls in order to access them from .net code? Thanks, Roshawn
4
by: Server Control | last post by:
Hi, I have a datagrid(within a user control) that has label controls. I have added hidden fields in the datagrid alongwitht the label control. I do some client side editing with javascript and...
2
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...
0
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...

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.