psot back

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
 
M

Mark Rae [MVP]

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

Roger

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

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

Top