CustomValidator and jscript confirm()

G

Guest

Hi newbie ASP.NET coder here...

Can someone tell me what I'm missing or what I'm doing wrong here?

I'm trying to validate based on a javascript confirm. The confirm box is
just an ok/cancel. Whether I press ok or cancel, I get the invalid page.
Help?

===================================>>

<script runat="server">
Private sub DoSomething(s as Object,e As EventArgs)
dim msg as string
if (Page.IsValid) then
label1.Text = "Did something"
Else
label1.Text = "Invalid something"
End if
end sub
</script>

<script LANGUAGE="JavaScript">
function confirmSubmit(source, Value)
{
var btMsg = "Client Validator"
var name=confirm(btMsg)
if (name==true)
{
Value.IsValid = True;
}
else
{
Value.IsValid = False;
}
}
</script>

<html>
<body>

<form runat="server">
<asp:TextBox id="tbUserID" TextMode="multiline" runat="server" /><br />
<asp:Button OnClick="DoSomeThing" Text="Submit" runat="server" />

<asp:CustomValidator id="ValidateUserID" runat="server"
ControlToValidate="tbUserID"
ClientValidationFunction="confirmSubmit"
Display="Dynamic"
Text="Invalid User ID"
Font-Name="verdana" Font-Size="10pt" runat="server"/>

<p><asp:label id="label1" runat="server" /></p>
</form>

</body>
</html>
 
S

Shiva

Quick check: Change True to true and False to false when assigning values to
Value.IsValid and then try.

Hi newbie ASP.NET coder here...

Can someone tell me what I'm missing or what I'm doing wrong here?

I'm trying to validate based on a javascript confirm. The confirm box is
just an ok/cancel. Whether I press ok or cancel, I get the invalid page.
Help?

===================================>>

<script runat="server">
Private sub DoSomething(s as Object,e As EventArgs)
dim msg as string
if (Page.IsValid) then
label1.Text = "Did something"
Else
label1.Text = "Invalid something"
End if
end sub
</script>

<script LANGUAGE="JavaScript">
function confirmSubmit(source, Value)
{
var btMsg = "Client Validator"
var name=confirm(btMsg)
if (name==true)
{
Value.IsValid = True;
}
else
{
Value.IsValid = False;
}
}
</script>

<html>
<body>

<form runat="server">
<asp:TextBox id="tbUserID" TextMode="multiline" runat="server" /><br />
<asp:Button OnClick="DoSomeThing" Text="Submit" runat="server" />

<asp:CustomValidator id="ValidateUserID" runat="server"
ControlToValidate="tbUserID"
ClientValidationFunction="confirmSubmit"
Display="Dynamic"
Text="Invalid User ID"
Font-Name="verdana" Font-Size="10pt" runat="server"/>

<p><asp:label id="label1" runat="server" /></p>
</form>

</body>
</html>
 

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