Calling Javascript

  • Thread starter Thread starter srini.venkatesan
  • Start date Start date
S

srini.venkatesan

I am trying to call a javascript from Datagrid which is using
OnUpdatecommand, I dont see update being invoked, what am I missing, Is
it the right way to call. I have just cut and pasted only the part of
the code. Thanks

In the class file:
public void DataGrid2_Edit(Object sender, DataGridCommandEventArgs e)
{
DataGrid2.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();

TableCell cell = (TableCell) e.Item.Controls[0];
System.Web.UI.WebControls.LinkButton lnk=
(System.Web.UI.WebControls.LinkButton ) cell.Controls[0];
lnk.Attributes.Add("onclick","javascript:confirm_update();");
}

Html:
</style>
<script language="javascript">
function confirm_update()
{
if(confirm("Are you sure you want to update?")==true)
return true;
else
return false;
}
</script>
</HEAD>
<BODY>
<form id="Form1" method="post" runat="server">
<h2>Customer Fleet Edit Screen For:
<asp:Label id="Label1" runat="server"
Width="112px">Label</asp:Label></h2>
<asp:datagrid id="DataGrid2" runat="server"
AutoGenerateColumns="false" OnUpdateCommand="DataGrid2_Update"
OnCancelCommand="DataGrid2_Cancel" OnEditCommand="DataGrid2_Edit"
HeaderStyle-BackColor="#aaaadd"
 
Not sure if this will fix it, but where you add the attribute for
onclick event, you aren't returning the result of the method.
So the clicking may not occur.

lnk.Attributes.Add("onclick","javascript:confirm_update();");

becomes

lnk.Attributes.Add("onclick","return confirm_update();");
 
The problem is that you are in a JavaScript blocking declaring a
JavaScript inline block. Just call the function. You only need the
JavaScript inline block for things like href in an anchor.
 
still not able to get it working.
I need to do other validation in the update, thats why I need to call
the javascript on the updateevent. Any other clues ?

Thanks
 
Is your javascript function have not been called or the page have been
posted back before your javascript have been called. Also please can u
tell me what the linkbutton tag client source contains (Anchor tag
that's been formed due to link button's html).
 
Anything in the quotes is JavaScript: onclick=""

Never put "javascript: " in there, because that's not JavaScript. It's
already JavaScript. You just need to call the function like
onClick="ConfirmUpdate( );" or if you need a return, go ahead.
 
Back
Top