Question

I have a User Control --> Aspx Page--> Master Page scenario. The User Control contains a GridView. I want to be able to call a javascript function when the Gridview "Select" linkbutton is clicked.

I am able to get this to work the first time the linkbutton is clicked, but every other subsequent click fails to call the javascript function.

I am currently registering my javascript function using the ASP.Net ScriptManager/ScriptManagerProxy method - Proper way to use JQuery when using MasterPages in ASP.NET?

Any ideas on why this fails after the first try?

Was it helpful?

Solution

Without code I'm not sure your implementation, but here's what I'd do:

LinkButton, like Button has an OnClientClick property that you can set to call client-side JavaScript before running the PostBack. But you don't have access to this when you are using a CommandField.

First, convert your CommandField (the one with the Select button) to a TemplateField. You should then be given a LinkButton or Button, which you can then set the OnClientClick property for.

I think this would be a lot simpler than doing registerscripts, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top