By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,948 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,948 IT Pros & Developers. It's quick & easy.

validation doesn't fire

P: n/a

validation doesn't fire

what's missing ?????
/////// ---- code -----///////////////////////////
Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click
If page.isValid then
.....
end if
//////// --form --- ///////////////////////
<asp:TextBox id="x_Card_Num" runat="server" Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator ID="x_Card_NumRequired" runat="server"
ControlToValidate="x_Card_Num"
ErrorMessage=""

ValidationGroup="orderform">*</asp:RequiredFieldValidator>

.....

<asp:validationSummary id="summary" runat="server"
ValidationGroup="orderform"
ShowmessageBox="False"
ShowSummary="True"
DisplayMode ="BulletList" />

<asp:ImageButton ID="btnSubmit" runat="server"
BorderWidth="0"
onclick="btnSubmit_Click"
ImageUrl="~/images/continue.gif" />
Jan 31 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
2 Things I see...

1. Your "Handles" clause on the btnSubmit event handler is commented so
there is a chance that this procedure isn't even being executed.
2. You don't need to write any code at all to get the
RequiredFieldValidator to work and usually don't need to check for
Page.IsValid because the client and server side validations would prevent
the page from processing.

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...
>
validation doesn't fire

what's missing ?????
/////// ---- code -----///////////////////////////
Sub btnSubmit_Click(sender As Object, e As
System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click
If page.isValid then
.....
end if
//////// --form --- ///////////////////////
<asp:TextBox id="x_Card_Num" runat="server" Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator ID="x_Card_NumRequired" runat="server"
ControlToValidate="x_Card_Num"
ErrorMessage=""

ValidationGroup="orderform">*</asp:RequiredFieldValidator>

....

<asp:validationSummary id="summary" runat="server"
ValidationGroup="orderform"
ShowmessageBox="False"
ShowSummary="True"
DisplayMode ="BulletList" />

<asp:ImageButton ID="btnSubmit" runat="server"
BorderWidth="0"
onclick="btnSubmit_Click"
ImageUrl="~/images/continue.gif" />

Jan 31 '07 #2

P: n/a
1. Your "Handles" clause on the btnSubmit event handler is commented so there is a chance that this procedure isn't even being
executed.
fortunately, other items in the procedure are working so I know the procedure is being processed....

2. You don't need to write any code at all to get the RequiredFieldValidator to work and usually don't need to check for
Page.IsValid because the client and server side validations would prevent the page from processing.
I guess that's where I'm stuck.
They're not firing ...The page goes through and ignores the required fields

>
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message news:u1**************@TK2MSFTNGP06.phx.gbl...
>>
validation doesn't fire

what's missing ?????
/////// ---- code -----///////////////////////////
Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click
If page.isValid then
.....
end if
//////// --form --- ///////////////////////
<asp:TextBox id="x_Card_Num" runat="server" Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator ID="x_Card_NumRequired" runat="server"
ControlToValidate="x_Card_Num"
ErrorMessage=""

ValidationGroup="orderform">*</asp:RequiredFieldValidator>

....

<asp:validationSummary id="summary" runat="server"
ValidationGroup="orderform"
ShowmessageBox="False"
ShowSummary="True"
DisplayMode ="BulletList" />

<asp:ImageButton ID="btnSubmit" runat="server"
BorderWidth="0"
onclick="btnSubmit_Click"
ImageUrl="~/images/continue.gif" />


Jan 31 '07 #3

P: n/a
If the validator is in "orderform" validation group, the Button should be in
the same group also? E.g it should also have
ValidationGroup="orderform"?

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:uv**************@TK2MSFTNGP03.phx.gbl...
>
>1. Your "Handles" clause on the btnSubmit event handler is commented so
there is a chance that this procedure isn't even being executed.

fortunately, other items in the procedure are working so I know the
procedure is being processed....

>2. You don't need to write any code at all to get the
RequiredFieldValidator to work and usually don't need to check for
Page.IsValid because the client and server side validations would prevent
the page from processing.

I guess that's where I'm stuck.
They're not firing ...The page goes through and ignores the required
fields

>>
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...
>>>
validation doesn't fire

what's missing ?????
/////// ---- code -----///////////////////////////
Sub btnSubmit_Click(sender As Object, e As
System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click
If page.isValid then
.....
end if
//////// --form --- ///////////////////////
<asp:TextBox id="x_Card_Num" runat="server"
Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator ID="x_Card_NumRequired" runat="server"
ControlToValidate="x_Card_Num"
ErrorMessage=""

ValidationGroup="orderform">*</asp:RequiredFieldValidator>

....

<asp:validationSummary id="summary" runat="server"
ValidationGroup="orderform"
ShowmessageBox="False"
ShowSummary="True"
DisplayMode ="BulletList" />

<asp:ImageButton ID="btnSubmit" runat="server"
BorderWidth="0"
onclick="btnSubmit_Click"
ImageUrl="~/images/continue.gif" />


Jan 31 '07 #4

P: n/a
Page.IsValid is the key to check in case client misses the client-side
validation. That's the server-side stop to prevent code from running if
validation fails at server-side.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Scott M." <s-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>2 Things I see...

1. Your "Handles" clause on the btnSubmit event handler is commented so
there is a chance that this procedure isn't even being executed.
2. You don't need to write any code at all to get the
RequiredFieldValidator to work and usually don't need to check for
Page.IsValid because the client and server side validations would prevent
the page from processing.

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...
>>
validation doesn't fire

what's missing ?????
/////// ---- code -----///////////////////////////
Sub btnSubmit_Click(sender As Object, e As
System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click
If page.isValid then
.....
end if
//////// --form --- ///////////////////////
<asp:TextBox id="x_Card_Num" runat="server" Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator ID="x_Card_NumRequired" runat="server"
ControlToValidate="x_Card_Num"
ErrorMessage=""

ValidationGroup="orderform">*</asp:RequiredFieldValidator>

....

<asp:validationSummary id="summary" runat="server"
ValidationGroup="orderform"
ShowmessageBox="False"
ShowSummary="True"
DisplayMode ="BulletList" />

<asp:ImageButton ID="btnSubmit" runat="server"
BorderWidth="0"
onclick="btnSubmit_Click"
ImageUrl="~/images/continue.gif" />

Jan 31 '07 #5

P: n/a
The default action is to do server-side validation as well, for just this
reason. There is no need to check for Page.IsValid on standard validation
controls.
"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:52**********************************@microsof t.com...
Page.IsValid is the key to check in case client misses the client-side
validation. That's the server-side stop to prevent code from running if
validation fails at server-side.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Scott M." <s-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>2 Things I see...

1. Your "Handles" clause on the btnSubmit event handler is commented so
there is a chance that this procedure isn't even being executed.
2. You don't need to write any code at all to get the
RequiredFieldValidator to work and usually don't need to check for
Page.IsValid because the client and server side validations would prevent
the page from processing.

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...
>>>
validation doesn't fire

what's missing ?????
/////// ---- code -----///////////////////////////
Sub btnSubmit_Click(sender As Object, e As
System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click
If page.isValid then
.....
end if
//////// --form --- ///////////////////////
<asp:TextBox id="x_Card_Num" runat="server"
Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator ID="x_Card_NumRequired" runat="server"
ControlToValidate="x_Card_Num"
ErrorMessage=""

ValidationGroup="orderform">*</asp:RequiredFieldValidator>

....

<asp:validationSummary id="summary" runat="server"
ValidationGroup="orderform"
ShowmessageBox="False"
ShowSummary="True"
DisplayMode ="BulletList" />

<asp:ImageButton ID="btnSubmit" runat="server"
BorderWidth="0"
onclick="btnSubmit_Click"
ImageUrl="~/images/continue.gif" />


Jan 31 '07 #6

P: n/a
Yes, it does validate but you do need to check Page.IsValid (or specific
validator's IsValid) to see if it passed or not (no one does that for you)
if you want to be 100% sure nothing gets pass the validation. That is, you
cannot rely solely on client-side validation.

Consider this example (TextBox, a couple of validators and a Button plus
Label):

<asp:TextBox ID="txtExpectingIntegers" runat="server" />
<asp:RequiredFieldValidator ID="reqINteger" runat="server"
ControlToValidate="txtExpectingIntegers" ErrorMessage="Insert something!" />
<asp:CompareValidator ID="cmpValInt" runat="server"
ControlToValidate="txtExpectingIntegers" Operator="DataTypeCheck"
Type="Integer" ErrorMessage="Please enter an integer!" />
<asp:Button ID="btnSend" runat="server" Text="Try it out"
OnClick="btnSend_Click" />

<asp:Label ID="lblMessage" runat="server" />

// Code

protected void btnSend_Click(object sender, EventArgs e)
{
//Testing for Page.IsValid here helps...
// if(!Page.IsValid)return;

try
{
int val = Int32.Parse(txtExpectingIntegers.Text);
lblMessage.Text ="We got an integer " + val.ToString();
}
catch(Exception ex)
{
lblMessage.Text = "Exception while parsing the integer:" +
ex.ToString();
}
}
If you now open it in in any normal browser with js enabled, of course with
standard scripts enabled it's catched & validated. But go now and disable
javascripts in your browser. Then type something non-number to the TextBox
and you'll see it blow, as Button's click is handled normally as if there
would be no validation. E.g nothing prevents the Button's click event from
running unless *you* check for the outcome of the validation (validation
message are displayed but page executes as-is). Think if it would be a
database operation dependant on the input user enters...

So to summarize: you do want to check IsValid at the server. Just running
validation isn't enough, you do need to know did it pass or not to decide
what's next (to let ValidationSummary display a nice message)

In case you don't still believe me, see this one:
http://msdn2.microsoft.com/en-us/library/7kh55542.aspx

There's this sentence

"ASP.NET performs validation on the server even if the validation controls
have already performed it on the client, so that you can test for validity
within your server-based event handlers. In addition, re-testing on the
server helps prevent users from being able to bypass validation by disabling
or changing the client script check."

Of course in normal intranet scenario these probably aren't issues, but I'd
think that being sure isn't too bad choice.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net



"Scott M." <s-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
The default action is to do server-side validation as well, for just this
reason. There is no need to check for Page.IsValid on standard validation
controls.
"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:52**********************************@microsof t.com...
>Page.IsValid is the key to check in case client misses the client-side
validation. That's the server-side stop to prevent code from running if
validation fails at server-side.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Scott M." <s-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>>2 Things I see...

1. Your "Handles" clause on the btnSubmit event handler is commented so
there is a chance that this procedure isn't even being executed.
2. You don't need to write any code at all to get the
RequiredFieldValidator to work and usually don't need to check for
Page.IsValid because the client and server side validations would
prevent the page from processing.

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...

validation doesn't fire

what's missing ?????
/////// ---- code -----///////////////////////////
Sub btnSubmit_Click(sender As Object, e As
System.Web.UI.ImageClickEventArgs) 'Handles btnSubmit.Click
If page.isValid then
.....
end if
//////// --form --- ///////////////////////
<asp:TextBox id="x_Card_Num" runat="server"
Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator ID="x_Card_NumRequired" runat="server"
ControlToValidate="x_Card_Num"
ErrorMessage=""

ValidationGroup="orderform">*</asp:RequiredFieldValidator>

....

<asp:validationSummary id="summary" runat="server"
ValidationGroup="orderform"
ShowmessageBox="False"
ShowSummary="True"
DisplayMode ="BulletList" />

<asp:ImageButton ID="btnSubmit" runat="server"
BorderWidth="0"
onclick="btnSubmit_Click"
ImageUrl="~/images/continue.gif" />

Feb 1 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.