psot back

  • Thread starter Thread starter Roger
  • Start date Start date
R

Roger

Hi
If anyone can help

Is there away to make javascript prevent a postback on a button,
i have tried putting the button in a <span> tag with onclick but it carrys
out the javascript functioon and then posts back even if i use return false;

I want javascript to do clientside valudation before posting back

cheers in advance

Roger
 
Is there away to make javascript prevent a postback on a button,
i have tried putting the button in a <span> tag with onclick but it carrys
out the javascript functioon and then posts back even if i use return
false;

I want javascript to do clientside valudation before posting back

<script type="text/javascript">
function validateForm()
{
if (...validation condition fails...)
{
alert('Validation failed');
return false;
}
</script>

<asp:Button ID="MyButton" runat="server" Text="Save" OnClick="MyButton_Save"
OnClientClick="return validateForm();" />
 
thanks very much simple really :)
Mark Rae said:
<script type="text/javascript">
function validateForm()
{
if (...validation condition fails...)
{
alert('Validation failed');
return false;
}
</script>

<asp:Button ID="MyButton" runat="server" Text="Save"
OnClick="MyButton_Save" OnClientClick="return validateForm();" />
 
Back
Top