Pregunta

I'm designing a page with forms for editing fields in a database. At first I was using FormView controls, but for various reasons I've changed them for DetailsView controls instead. These are so much quicker to code and the code is much tidier, because you just add a Boundfield for each field you want to display. No textboxes, labels, etc. So far so good.

However, the textboxes in my FormViews all had the onchange property specified, which called a JavaScript function. Basically it was the mechanism to alert a user that changes had been made and needed saving, and it worked perfectly.

Unfortunately, you can't add the onchange property to a DetailsView Boundfield. I've tried adding it programmatically in code behind (VB) in the DataBound event of the DetailsView, working on the theory that when the page is loaded the Boundfields are rendered as textboxes but, as expected, it doesn't work.

Can anyone suggest a way to replicate the functionality of the textboxes in my FormViews, calling a JavaScript function when text in a Boundfield is changed? I'd really like to stick with DetailsViews and Boundfields if I can. And if I could achieve this in code-behind, perhaps iterating through the fields to add the functionality, that'd mean just a few lines of code for each DetailsView, rather than adding it declaratively for every Boundfield (there are LOTS!).

¿Fue útil?

Solución

This was way easier than I thought. It's possible to add the onchange property to the DetailsView itself. Once that's done, any change to any field within the DetailsView calls the JavaScript function.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top