question about "return false"

B

Ben

Hi;

I use ain asp.net the CreateUserWizard control for new users. When it's
done, i want to redirect them to another page (modifyprofile.aspx). This
works with the code below.

My question is: if i suppress the line "return false" in the javascript
function profile(), the user is created but not redirected to the other aspx
page. Can anybody explain me why?

Thanks
Ben


<asp:Button ID="ContinueButton" runat="server" CausesValidation="false"
CommandName="Continue"
Text="Log in and create your profile" OnClientClick="return profile()"
ValidationGroup="CreateUserWizard1" />

<script language="javascript" type="text/javascript">
function profile()
{
window.location.href="modifyprofile.aspx"
return false
}
</script>
 
T

Tim Williams

Hard to say exactly, without seeing the client-side HTML generated by the
asp tag, but in general returning false to an onclick event will cancel the
default action associated with the clicked object.

Tim
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Ben said:
Hi;

I use ain asp.net the CreateUserWizard control for new users. When it's
done, i want to redirect them to another page (modifyprofile.aspx). This
works with the code below.

My question is: if i suppress the line "return false" in the javascript
function profile(), the user is created but not redirected to the other aspx
page. Can anybody explain me why?

Thanks
Ben


<asp:Button ID="ContinueButton" runat="server" CausesValidation="false"
CommandName="Continue"
Text="Log in and create your profile" OnClientClick="return profile()"
ValidationGroup="CreateUserWizard1" />

<script language="javascript" type="text/javascript">
function profile()
{
window.location.href="modifyprofile.aspx"
return false
}
</script>

Returning false from the event prevents the button from making a postback.
 
D

Dr J R Stockton

In microsoft.public.scripting.jscript message <#BZMyK4fHHA.3372@TK2MSFTN
My question is: if i suppress the line "return false" in the javascript
function profile(), the user is created but not redirected to the other aspx
page. Can anybody explain me why?

When a function is left otherwise than by a return statement with an
argument, it returns the special value <undefined>. In some
circumstances, <undefined> and <false> are equivalent; in others, they
are not. The rest of your code evidently falls into the second
category.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
E

Evertjan.

Dr J R Stockton wrote on 16 apr 2007 in
microsoft.public.scripting.jscript:
In microsoft.public.scripting.jscript message


When a function is left otherwise than by a return statement with an
argument, it returns the special value <undefined>. In some
circumstances, <undefined> and <false> are equivalent; in others, they
are not. The rest of your code evidently falls into the second
category.

More specificly, they are not equivalent,
but the code that interprets the returned value
can interpret anything else than specific <true> or <false>
as specifically specified for that calling function.

<onclick>, <onsubmit>, etc,
usually intepret anything else than a specific <false> as true,
while <if>, <while>, do not:


<script type='text/javascript'>
if (0) alert(true) // 0 -> false: NO ALERT
</script>

<a href='http://cnn.com/'
onclick='return 0'>
cnn</a>

0 -> true: link is honoured
 

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