473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

RequiredValidator not working

I have the following:

<asp:textbox id="ProfileName" columns="45" runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="ProfileName"
Display="Dynamic"
Text="Name Required"
runat="server" />

I also have an imagebutton that goes to a routine to save a record

<asp:ImageButton ID="SaveRecord" runat="server" Visible="true"
OnClick="ModifyRecord_Click" ImageUrl="../../buttons/SaveChanges_0.gif" />

I put nothing in the ProfileName field and it still goes to the function
ModifyRecord_Click instead of displaying the "Name Required" message.

Why is it not working?

Thanks,

Tom
Nov 19 '05 #1
7 3545
TJS
I have a similar problem and wonder if this is like mine.

Are you having this problem in both IE and Firefox browsers ?
Are you prepopulating the field for the user to show the current value from
a datastore ?
Nov 19 '05 #2
"TJS" <no****@here.com> wrote in message
news:uJ**************@TK2MSFTNGP15.phx.gbl...
I have a similar problem and wonder if this is like mine.

Are you having this problem in both IE and Firefox browsers ?
Are you prepopulating the field for the user to show the current value
from a datastore ?


Actually,

It does it with both.

But I also was getting an error before in the function the button was
calling, so I assume the validator wasn't being called.

I assumed that because I got the error, the validator didn't work.

What is happening is that the function is being called after the Validator
has run?

I thought if there was an error, the function wouldn't be called. Am I
wrong here?

Thanks,

Tom

Nov 19 '05 #3
TJS
You're right, the function should not be called if the page is not valid

since it fails in both browsers, and you aren't prefilling the form, I would
need to see your code for "ModifyRecord_Click" to determine of the problem
is there.


Nov 19 '05 #4
"TJS" <no****@here.com> wrote in message
news:uN*************@TK2MSFTNGP15.phx.gbl...
You're right, the function should not be called if the page is not valid

since it fails in both browsers, and you aren't prefilling the form, I
would need to see your code for "ModifyRecord_Click" to determine of the
problem is there.


Actually, what I did to make it work is:

Sub ModifyRecord_Click(sendor as Object, e as ImageClickEventArgs)

if not Page.isValid then
exit Sub
End If

I guessed the function does get called, so I just added that code to solve
the problem.

Tom
Nov 19 '05 #5
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
"TJS" <no****@here.com> wrote in message
news:uN*************@TK2MSFTNGP15.phx.gbl...
You're right, the function should not be called if the page is not valid

since it fails in both browsers, and you aren't prefilling the form, I
would need to see your code for "ModifyRecord_Click" to determine of the
problem is there.


Actually, what I did to make it work is:

Sub ModifyRecord_Click(sendor as Object, e as ImageClickEventArgs)

if not Page.isValid then
exit Sub
End If

I guessed the function does get called, so I just added that code to solve
the problem.

Tom

Nov 19 '05 #6
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
"TJS" <no****@here.com> wrote in message
news:uN*************@TK2MSFTNGP15.phx.gbl...
You're right, the function should not be called if the page is not valid

since it fails in both browsers, and you aren't prefilling the form, I
would need to see your code for "ModifyRecord_Click" to determine of the
problem is there.

Actually, what I did to make it work is:

Sub ModifyRecord_Click(sendor as Object, e as ImageClickEventArgs)

if not Page.isValid then
exit Sub
End If

I guessed the function does get called, so I just added that code to solve
the problem.


Now the problem is in my other routine, which is called by my LinkButton
(the Modify routine was called by an ImageButton).

The code is the same:

Sub DeleteProfile_Click(sender as Object, e as EventArgs)
trace.warn("inside SelectProfile")

if not Page.isValid then
exit Sub
End If

But when I do it I get the error:

Page.IsValid cannot be called before validation has taken place. It should
be queried in the event handler for a control with CausesValidation=True or
after a call to Page.Validate.

So in the Modify function, the validate function is being called and in the
Delete function it is not ???????

Tom Tom

Nov 19 '05 #7
The method Page.Validate() is called automatically by each of Microsoft's
submit controls (Button, ImageButton, and LinkButton) unless you set
CausesValidation to false. If its not called, you cannot use Page.IsValid as
you've found.

The submit controls call it in their OnClick method (which then fires your
Click event handler). It runs after Page_Load.
- Make sure CausesValidation=true or you call Page.Validate() before calling
Page.IsValid
- Don't call any of this from within Page_Load. Let it happen in the post
back event methods.
- If you are using CausesValidation=false because you don't want to validate
every validator, call individual validator's Validate() methods. Then check
the IsValid property on those individual validators.
- This is all server side code. It should not be affected by the browser
type.
- It is possible that if javascript is not working, your Click post back
event will not run. This happens when your submit control calls
__doPostBack() on the client-side to set itself up for server side
processing. Without javascript running, __doPostBack() never runs.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"tshad" <ts**********@ftsolutions.com> wrote in message
news:OF****************@TK2MSFTNGP14.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
"TJS" <no****@here.com> wrote in message
news:uN*************@TK2MSFTNGP15.phx.gbl...
You're right, the function should not be called if the page is not valid

since it fails in both browsers, and you aren't prefilling the form, I
would need to see your code for "ModifyRecord_Click" to determine of the
problem is there.


Actually, what I did to make it work is:

Sub ModifyRecord_Click(sendor as Object, e as ImageClickEventArgs)

if not Page.isValid then
exit Sub
End If

I guessed the function does get called, so I just added that code to
solve the problem.


Now the problem is in my other routine, which is called by my LinkButton
(the Modify routine was called by an ImageButton).

The code is the same:

Sub DeleteProfile_Click(sender as Object, e as EventArgs)
trace.warn("inside SelectProfile")

if not Page.isValid then
exit Sub
End If

But when I do it I get the error:

Page.IsValid cannot be called before validation has taken place. It should
be queried in the event handler for a control with CausesValidation=True
or after a call to Page.Validate.

So in the Modify function, the validate function is being called and in
the Delete function it is not ???????

Tom
Tom


Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SStory | last post by:
Is there no way to require a checkbox to be checked in ASP.NET? The requiredvalidator control doesn't work for it--should I make a server--roundtrip for that and check during the btn_click event? ...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
1
by: Elie Medeiros via .NET 247 | last post by:
Hi there, I have written a custom validator function to validate a datefrom a user-filled field. The function tries to parse the dateand if it can't, sets (serverValidateEventArgs)e.IsValid...
3
by: TJS | last post by:
I am finding that the serverside requiredvalidator doesn't fire in the firefox browser, and user request proceeds through to my updateProfile method. Validation is working correctly in the IE...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
4
by: Shimon Sim | last post by:
hi It should be easy but I can't make it work. I have DropDownList. I set first with text and value "Select". Then I add RequiredValidator and set it InitialValue to "Select" and I expect that the...
2
by: Niraj Sikotara | last post by:
hello, i'm using ASP.NET 2.0, and have placed validators on a page that are not working correctly in FireFox (1.5.0.7) the page can be downloaded from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.