Archive for January, 2010

GridView – Edit command won’t work, Javascript work around

January 28, 2010

I was using the gridview option AutoGenerateEditButton=”true” .

It used to work for the gridview in question. Today I had an issue, and believe I saw a post that is similar to my situation where gridview itself had an issue

msft reply-2007

The behavior I saw is illustrated by the following images. When I mouse over the generated links, at the base of the page I can see the javascript function that would be called. (note that the update command is missing).




My workaround is to perform the same doPostBack function call as the generated links performed.

Here is the code:


var gvUniqueId; // we need the ctl00$ControlPlaceHolder1$gvQueries string for the gridview
gvUniqueId = '<%=gvQueries.UniqueID %> ' ;
var cmd;

function handle_gvUpdate(rowid) {

cmd = 'Update$' + rowid;

__doPostBack(gvUniqueId, cmd);


function handle_gvEdit(rowid) {

cmd = 'Edit$' + rowid;

__doPostBack(gvUniqueId, cmd);


function handle_gvCancel(rowid) {

cmd = 'Cancel$' + rowid;

__doPostBack(gvUniqueId, cmd);



<asp:GridView ID="gvQueries" runat="server"NOTA BENE: if you have problems pasting any of this code, contact me and I’ll send you the exact script. It’s difficult for me to paste code into wordpress.








<asp:HyperLinkField DataNavigateUrlFields=”QueryID”


DataTextField=”QueryID” DataTextFormatString=”view” Text=”View”

Target=”_blank” />

<asp:TemplateField HeaderText=”Edit” >


<a href=’javascript:handle_gvCancel(<%# Container.DataItemIndex %>)’>Cancel</a>

<a href=’javascript:handle_gvUpdate(<%# Container.DataItemIndex %>)’>Update</a>



<a href=’javascript:handle_gvEdit(<%# Container.DataItemIndex %>)’>Edit</a>



Ajax problem with <%= in HEAD

January 12, 2010

I included some javascript files into my master file with tags like this:

<script src='' language="javascript" type="text/javascript" >

(the purpose of that is to include the gui.js file from the master file, even though we might open a page in a subdirectory)

PROBLEM – when I added an Ajax control to a child page, I got the dreaded “The Controls collection cannot be modified because the control contains code blocks ”

SIMPLE SOLUTION – a Telerik website said to just move the offending code from the HEAD region into the BODY region, and that worked for me.

Rick Strahl has some great discussion of this: