I'm populating a GridView programmatically and adding a button to the last row:
ButtonField bc = new ButtonField();
bc.ButtonType = ButtonType.Button;
bc.Text = "Edit";
bc.CommandName = "EditAsset";
grid.Columns.Add(bc);
In the markup I specify a handler:
<asp:GridView ID="gvListView" OnRowCommand="gvListView_RowHandler" runat="server"></asp:GridView>
I add the handler to the codebehind:
protected void gvListView_RowHandler(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditAsset")
{
}
}
When I run it and click a button in the gridview, I get a javascript error that __doPostBack is undefined. Anyone know why the js for that wouldn't be generated?
The dynamically generated button call looks like this:
onclick="javascript:__doPostBack('lvStuff$gvListView','EditAsset$0')"
edit: The doPostBack was generated on the page, but has some sort of comment around it?
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
Well, I feel silly. The problem was that I was trying to end my earlier script tags in the header wrong. I was doing this:
Instead of this:
Which was causing the javascript to fail. Didn't realize you couldn't close script tags in the xml fashion.