Problem with Textbox Attributes Collections

G

Guest

I am wondering if anyone has encountered a similar problem to the one that I am having. I have an ASP.NET page which has a table and a dropdownlist that was added at design time. The majority of the rows in the table are then generated at run-time based on a SQL query from a Jet database, and similarly the dropdownlist is filled at run-time

Then I follow these steps
1. Loop through the records returned by the OleDbDataReade
2. Setup a control based on a [Type] field in the SQL Query - either a multiline textbox, singleline textbox or an option grou
3. Add the control to a HtmlTableCell; then to a HtmlTableRow; and then to the table

At the top of each the loop, I check to see if a singleline textbox was added on the last loop completed. In the case that it was, I add an "onKeyPress" attribute which causes the textbox to call a client-side javascript function onKeyPress, which in-turn causes the focus to shift to the next control if a single digit is entered into the singleline textbox

Everything works PERFECTLY on the first page_load. The problems begin to occur on successive page_loads. The dropdownlist generates a parameter for the SQL Query and has AutoPostBack set to true. In the Page_Load, I recreate the table full of controls based on a new SQL Query with the parameter from the dropdownlist

The majority of controls still work perfectly. HOWEVER, I find that the attribute collection becomes slightly confused and certain controls have an onKeyPress event, even though I didn't add an attribute to the newly create control. I have determined that the function is actually referring to a control on the previous page load ... even though ALL of the controls were created uniquely on the current page_load

These are the three types of onKeyPress values that I use
txtNew.Attributes.Add("onKeyPress", "return mdlCheckKey(this, event)"
txtNew.Attributes.Add("onKeyPress", "return mdlCheckKeyOpt(this, event, 'optY" + reaData("QID").ToString() + "')"
txtNew.Attributes.Add("onKeyPress", "return mdlCheckKeyOpt(this, event, 'txtOther" + reaData("QID").ToString() + "')"

The first line is the one that is used predominantly, however, it is the bottom two that have allowed me to identify that the problem attributes are actually coming from the previous page_load. (On the first load, for example, the unqiue [QID] for each record will range from 1-25, then if pick another item in the dropdownlist, the [QID] will range from 26-50. However, on the second page_load, some of the controls will have client-side onKeyPress events which point to optY14 which was a control on the previous page_load.

It is a bit hard to post all of the code for the page as it is reliant on the database that supports it

Regard
PR
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,377
Latest member
Zebacus

Latest Threads

Top