I am using RegisterClientScriptBlock to send a JS alert to the user when the users goes into edit mode on a gridview, but it causes my page to error for some reason and I can't figure out why...
This is the method that causes the problem. The error occurs in the last line where the script is registered. (If I comment this out the page works fine!)
protected void EditRecord(object sender, GridViewEditEventArgs e)
{
gvStockItems.EditIndex = e.NewEditIndex;
// Gather current Search info
string strPartNo = Session["currentSearchTerm"].ToString();
BindData();
gvStockItems.SelectedIndex = gvStockItems.EditIndex;
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "thisIsTest", "<script language=\"text/javascript\">alert(\"oops\");</script>");
}
The error that is thrown in the JS console is
Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
It also says that this error occurred in Error$Create in the ScriptResource.axd, but I think this is an error that occurs on reporting what the real issue is, so I'm completely stumped.
Any help is greatly appreciated. Thanks.