469,934 Members | 1,974 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Calling Javascript

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_u pdate();");
}

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"

Oct 5 '06 #1
5 1522
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_u pdate();");

becomes

lnk.Attributes.Add("onclick","return confirm_update();");

Oct 5 '06 #2
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.

On Oct 5, 5:45 pm, "Steven Nagy" <learndot...@hotmail.comwrote:
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_u pdate();");

becomes

lnk.Attributes.Add("onclick","return confirm_update();");
Oct 5 '06 #3
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

q wrote:
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.

On Oct 5, 5:45 pm, "Steven Nagy" <learndot...@hotmail.comwrote:
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_u pdate();");

becomes

lnk.Attributes.Add("onclick","return confirm_update();");
Oct 5 '06 #4
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).

sr**************@gmail.com wrote:
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

q wrote:
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.

On Oct 5, 5:45 pm, "Steven Nagy" <learndot...@hotmail.comwrote:
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_u pdate();");
>
becomes
>
lnk.Attributes.Add("onclick","return confirm_update();");
Oct 6 '06 #5
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.
sr**************@gmail.com wrote:
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

q wrote:
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.

On Oct 5, 5:45 pm, "Steven Nagy" <learndot...@hotmail.comwrote:
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_u pdate();");
>
becomes
>
lnk.Attributes.Add("onclick","return confirm_update();");
Oct 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Julia Briggs | last post: by
5 posts views Thread by Krishna | last post: by
1 post views Thread by desmcc | last post: by
4 posts views Thread by Martin Feuersteiner | last post: by
13 posts views Thread by ukrbend | last post: by
5 posts views Thread by Newbie Coder | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.