Saturday, March 24, 2012

Ajax and Tables

I have a form on a page, which contains a table. Within that table, I want the user to be able to press a button, and then change the value in one of the cells. (The cells are all populated from database, and i need to write the value back to the database as well)

I have managed to use AJAX to allow the user to click on a button, which hits a page and changes the cell from a value, to an text <Input> and a button <Input>.

My problem is that when i try and use the value that the user has entered into the text input, I keep getting javascript errors saying that the name of my Input is not valid...

Hope this makes some sort of sense?

Cheers

Norm

This post was edited because it is a repeat of the post below. Be nice if it could have been deleted.


It makes sense if there are controls on the page that would create unique ID's for child controls, such as a Repeater or a MultiView. Without your ASPX code we can only guess.

If you cannot find the ID with a $get, I suspect that you have done something like that because it is unlikely that you created the id for every control in every cell in your table. Every id on the page needs to be unique. If you check the server ClientID property of the control you are looking at you'll probably find that it has been rendered with underscores and various parentId's. You can use this ClientId directly but it will not be the same id if you alter your page in the future and do something like embed the table in a tab control, or change it in other subtle ways.

My personal preference is to use a custom control which creates a known JavaScript variable for each control, but that may be more exotic than you need.

Another way is know the row in the table you want to address and address the cell numerically. Then find the child control by a name= that you have assigned to controls of the same type.

And lastly, bind something on your page to server side code such as Javascript function call which uses the ClientID and is attached to each control. I don't like to use this method however, because it's a regression to mixed code from ASP days.

If none of the above is the case, then the community needs to see the ASPX code and codebehind (preferably reduced to a working example with only the essentials)

No comments:

Post a Comment