Button Click Event

Y

Yama

Hi,

I have a button which is a server-side control. If a client-side error on a
form is produced and a javascript (client-side) is fired how do I avoid the
server-side button_client event to occur? (that is because the page gets
refreshed for no reason even if I say do nothing)

Thank you,

Yama
 
O

Oliver

Hi Yama,

If you don't want the post to go ahead, use

return false;

from the JavaScript function.


Hi,

I have a button which is a server-side control. If a client-side error on a
form is produced and a javascript (client-side) is fired how do I avoid the
server-side button_client event to occur? (that is because the page gets
refreshed for no reason even if I say do nothing)

Thank you,

Yama
 
Y

Yama

Hi Oliver,

I am returning false. Here is what I am doing...

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="_index.aspx.vb"
Inherits="Demo.__index"%>
<html><head><title>Validate</tile>
<script language="JavaScript" type="text/JavaScript">
<!-- // Hide older browser
function validate()
{
alert("Client-Side validation!");
return false;
}
}
//-->
</script>
<body>
<table>
<tr valign="top">
<td align="center" bgcolor="#ffffff" colspan="2"><br>
<asp:button id="cmdRunReport" runat="server" text="Run
Report"></asp:button><br>
<br>
</td>
</tr>
</table>
</body>
</html>

Behind-Code

'/// <summary>
'/// The main entry point for the application.
'/// First validate on client-side
'/// </summary>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'--// If the page has already loaded do not execute it again
If Not Page.IsPostBack Then
cmdRunReport.Attributes("onclick") = "validate();"
End If
End Sub


'/// <summary>
'/// Upon click "Run Report" The user is redirected to a "Loading..." page.
'/// </summary>

Private Sub cmdRunReport_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdRunReport.Click
Response.Redirect("Loading.aspx?URL=Invoice.aspx?")
End Sub

The problem is that when I click on the button is will execute the validate
client-side function but it will also execute the server-side
cmdRunReport_Click event. How can I prevent this from happening?

Yama
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top