null element id for DataGrid ButtonColumns

roflzorto

New Member
I have a bit of JavaScript in one of my pages that avoids the problem of users double-clicking buttons on a form and causing double submissions during asynchronous postbacks:\[code\]var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_initializeRequest(InitializeRequest); prm.add_endRequest(EndRequest);\[code\]var btn;function InitializeRequest(sender, args) { document.body.style.cursor = "wait"; var btnId = args._postBackElement.id; btn = document.getElementById(btnId); if (btn != null && (btn.type == "button" || btn.type == "submit")) btn.disabled = true;}function EndRequest(sender, args) { document.body.style.cursor = "default"; if (btn != null) btn.disabled = false;}\[/code\]\[/code\]This isn't working with DataGrid ButtonColumns. document.getElementById(btnId) returns null for those.If I use a TemplateColumn and put a Button control inside, that works fine.Looking at the HTML that gets rendered for the DataGrid, I can see that ASP.NET isn't outputting an onclick for the ButtonColumn, where it does do so for a Button inside a TemplateColumn:ButtonColumn:<input type="submit" name="ctl00$placeholderContent$dgCommittees$ctl03$ctl00" value="http://stackoverflow.com/questions/768738/Edit" />Button in TemplateColumn:<input type="submit" name="ctl00$placeholderContent$dgCommittees$ctl03$cmdDelete" value="http://stackoverflow.com/questions/768738/Delete" onclick="return confirm('Are you sure you wish to delete this committee?'); WebForm_DoPostBackWithOptions( new WebForm_PostBackOptions("ctl00$placeholderContent$dgCommittees$ctl03$cmdDelete", "", true, "", "", false, false))" id="ctl00_placeholderContent_dgCommittees_ctl03_cmdDelete" />Obviously the answer to "how do I make this work?" is to simply replace all my ButtonColumns with Buttons in TemplateColumns.I'm curious if anyone knows why ASP.NET renders ButtonColumns this way though, and if there's some way to get it to render them the same as Buttons.
 
Back
Top