Calling Javascript

  • Thread starter srini.venkatesan
  • 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"
 
S

Steven Nagy

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();");
 
Q

q

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.
 
S

srini.venkatesan

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
 
D

deepak.programming

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).
 
Q

q

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top