i want to validate a textbox like this:
<asp:TextBox ID="vrg" runat="server" Width="495px" TextMode=MultiLine/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="vrg"
Text="*" />
<asp:Button ID="Button1" runat="server" Text="go" />
This works: validation occurs on client side (no postback).
Now i want to perform some other checks with Javascript, so o added a
clientonclick like this:
<asp:Button ID="Button1" runat="server" OnClientClick="return test()"
Text="go" />
Whatever the code of function test() contains (actually it contains some
check on other texbox and also "return false", but can even be empty), from
now when clicking on the button, the validation still occurs but each time
with a postback (i checked with Page.IsPostabck).
I even tried with property Enable Client script=true (which is the default
value).
Why does that happen and how to prevent postback without removing the
javascript?
Thanks
Chris
<asp:Button
ID="Button1"
runat="server"
OnClientClick="if (!test()) return false;"
Text="go" />
if test returna true the validation will run, if false, not. if you
always want validation to run, don't return.
-- bruce (sqlwork.com)
let me show you the real code: (i tried with if (!test() .. and if(test() ..
There are two types in the dropdownlist: if type 1 is chosen, then the
items typed in the textbox must contain at least a ';'.
In no case, the textbox may remain empty.
<asp:TextBox ID="vrg" runat="server" TextMode=MultiLine/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="vrg"
<asp:DropDownList ID="type" runat="server">
<asp:ListItem Text="choose" Value="choose" />
<asp:ListItem Text="type 1" Value="type 1" />
<asp:ListItem Text="type 2" Value="type 2" />
</asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredFieldValidator3"
ControlToValidate="type" EnableClientScript=true
InitialValue="choose" text="*" runat=server>
<asp:Button ID="Button1" runat="server" OnClientClick="if (test()) return
false;" Text="go /> (no ! before test())
<script language="javascript" type="text/javascript">
function test()
{
var vrg=document.getElementById("tw").value
var type=document.getElementById("type").value
if (type=="type 1")
{
if (vrg.indexOf(";")==-1)
{
alert("the items must be separated with a ; ")
//return false ???
}
}
}
</script>
If you could place in this code the right thing to make it work ....?
Thanks again.
"bruce barker" <nos...@nospam.com> schreef in bericht
news:eNQDkjWx...@TK2MSFTNGP03.phx.gbl...
> if you decide to answer my question (with thanks), can't you go till
> the end because i'm still not helped at this point. The purpose is to
> give a solution, no?
>
The purpose of what? Usenet?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Hi,
People rally like client-side validation. It looks great and creates a better
overall user experience. The problem, however, is that it does not work with
all browsers. Not all browsers support JavaScript, and different versions of
browsers support different versions of javascript, so client-side validation
is never guranteed to work.
The validation controls automatically generate both client-side and server-
side code. If a browser is capable of supporting javascript, client-side
validation scripts are automatically sent to the browser. If the browser is
incapable of supporting javascript, the validation routines are automatically
implemented in server-side code.
However, the client-side validation works only with Microsoft Internet
Explorer version 4.0 and higher.
Database programming Using Visual basic 2005 and Csharp 2005
http://www.vkinfotek.com
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200707/1