How to run a CLient Side Function for a <asp:button >

  • Thread starter Thread starter RSB
  • Start date Start date
R

RSB

Hi Every one,

Having tuff time to make this work ..
i want to have a button and on my form say Delete button. So once i click on
it i want to confirm "Are you sure?" on the Client Side and if client select
"Cancel" then i want to ignore the action and if "OK" selected then i want
to Execute a Server side Event or Procedure.
Now what is happening here is for "Delete1" button (in my code) even if
Client Select Cancel it is still submitting the request...
and i am getting an error for the <asp:Button> control.
Please help me...


This is what i am doing..

<%@ Page Language="vb" AutoEventWireup="false" src="mypage.aspx.vb"
Inherits="mypage"%>

<SCRIPT language="javascript">
function buttonDelete()
{
if (!(window.confirm("Are You sure u want to delete?")))
{
return(false);
}
}

</SCRIPT>

<HTML>
<BODY>
<form id="Form1" name="Form1" method="post" runat="server">

<table >
<tr>
<td >
<asp:label id="lbl1" runat="server" >Name:</asp:label></td>
<td >
<asp:textbox id="txtName" runat="server" ></asp:textbox>
</td>
</tr>
<tr>
<td >
<INPUT name="cmdDelete1" type="submit" Value="Delete1"
onClick="javascript:buttonDelete()" onserverclick="buttonDeleteServer()">
<asp:button name ="cmdDelete" id="cmdDelete" runat="server"
Text="Delete" onClick="javascript:buttonDelete()"
onserverclick="buttonDeleteServer()" > </asp:button>
</td>
</tr>
</form>
</BODY>
</HTML>



Thank you in advance

RSB
 
Remove "onclick" property from the cmdDelete object in your aspx

Put this in your Page_Load method (C#)

cmdDelete.Attributes.Add("onclick", "return buttonDelete();")


----- RSB wrote: ----

Hi Every one

Having tuff time to make this work .
i want to have a button and on my form say Delete button. So once i click o
it i want to confirm "Are you sure?" on the Client Side and if client selec
"Cancel" then i want to ignore the action and if "OK" selected then i wan
to Execute a Server side Event or Procedure
Now what is happening here is for "Delete1" button (in my code) even i
Client Select Cancel it is still submitting the request..
and i am getting an error for the <asp:Button> control
Please help me..


This is what i am doing.

<%@ Page Language="vb" AutoEventWireup="false" src="mypage.aspx.vb
Inherits="mypage"%><SCRIPT language="javascript"
function buttonDelete(

if (!(window.confirm("Are You sure u want to delete?"))

return(false)



</SCRIPT><HTML><BODY><form id="Form1" name="Form1" method="post" runat="server"><table ><tr><td ><asp:label id="lbl1" runat="server" >Name:</asp:label></td><td ><asp:textbox id="txtName" runat="server" ></asp:textbox></td></tr><tr><td ><INPUT name="cmdDelete1" type="submit" Value="Delete1
onClick="javascript:buttonDelete()" onserverclick="buttonDeleteServer()"><asp:button name ="cmdDelete" id="cmdDelete" runat="server
Text="Delete" onClick="javascript:buttonDelete()
onserverclick="buttonDeleteServer()" ></asp:button></td></tr></form></BODY></HTML



Thank you in advanc

RS
 
Hi Suresh
Thanks,
So how do i execute a Client Side function then... For the <ASP:Button>
Thanks again
RSB

Remove "onclick" property from the cmdDelete object in your aspx.

Put this in your Page_Load method (C#).

cmdDelete.Attributes.Add("onclick", "return buttonDelete();");



----- RSB wrote: -----

Hi Every one,

Having tuff time to make this work ..
i want to have a button and on my form say Delete button. So once i
click on
it i want to confirm "Are you sure?" on the Client Side and if client
select
"Cancel" then i want to ignore the action and if "OK" selected then i
want
to Execute a Server side Event or Procedure.
Now what is happening here is for "Delete1" button (in my code) even
if
Client Select Cancel it is still submitting the request...
and i am getting an error for the <asp:Button> control.
Please help me...


This is what i am doing..

<%@ Page Language="vb" AutoEventWireup="false" src="mypage.aspx.vb"
Inherits="mypage"%><SCRIPT language="javascript">
function buttonDelete()
{
if (!(window.confirm("Are You sure u want to delete?")))
{
return(false);
}
}

Name:</asp:label></td><td ><asp:textbox id="txtName" runat="server"
</asp:textbox></td></tr><tr><td ><INPUT name="cmdDelete1" type="submit"
Value="Delete1"
onClick="javascript:buttonDelete()"
onserverclick="buttonDeleteServer()"><asp:button name ="cmdDelete"
id="cmdDelete" runat="server"
Text="Delete" onClick="javascript:buttonDelete()"
onserverclick="buttonDeleteServer()"
</asp:button></td></tr></form></BODY></HTML>



Thank you in advance

RSB
 
Hi Suresh,
Thanks it worked.... :o))
Ignore the other Post...
Thanks Again

RSB

Remove "onclick" property from the cmdDelete object in your aspx.

Put this in your Page_Load method (C#).

cmdDelete.Attributes.Add("onclick", "return buttonDelete();");



----- RSB wrote: -----

Hi Every one,

Having tuff time to make this work ..
i want to have a button and on my form say Delete button. So once i
click on
it i want to confirm "Are you sure?" on the Client Side and if client
select
"Cancel" then i want to ignore the action and if "OK" selected then i
want
to Execute a Server side Event or Procedure.
Now what is happening here is for "Delete1" button (in my code) even
if
Client Select Cancel it is still submitting the request...
and i am getting an error for the <asp:Button> control.
Please help me...


This is what i am doing..

<%@ Page Language="vb" AutoEventWireup="false" src="mypage.aspx.vb"
Inherits="mypage"%><SCRIPT language="javascript">
function buttonDelete()
{
if (!(window.confirm("Are You sure u want to delete?")))
{
return(false);
}
}

Name:</asp:label></td><td ><asp:textbox id="txtName" runat="server"
</asp:textbox></td></tr><tr><td ><INPUT name="cmdDelete1" type="submit"
Value="Delete1"
onClick="javascript:buttonDelete()"
onserverclick="buttonDeleteServer()"><asp:button name ="cmdDelete"
id="cmdDelete" runat="server"
Text="Delete" onClick="javascript:buttonDelete()"
onserverclick="buttonDeleteServer()"
</asp:button></td></tr></form></BODY></HTML>



Thank you in advance

RSB
 
Back
Top