Netnoobie Posted June 13, 2003 Posted June 13, 2003 Hello all. Im trying to (what I think is simple, maybe I'm wrong) do a validation when the user tabs off of a textbox. This validation is a database check to make sure that the entered text is valid based on internal criteria. I can't see to get into custom validator code while running it, and for some reason what I did just doesn't look and feel correct. How could I call up some sort of validator when the textbox is tabbed off of? And also validators retun boolean values right? Like IsValid = True? I need to use server side validation because of the database, but I can't seem to link the tabbing off of the textbox with firing the validation event...then marking the page invalid then and showing it. I'm using this method for an editeable datagrid as well as regular text boxes on a form. This means I'm really needing be able to fire everything without a submit button as I seen in examples everywhere. I've never really played with custom validators before and I'm felling really lost. Thanks! Bryan Quote
wyrd Posted June 13, 2003 Posted June 13, 2003 I could be wrong, but as far as I know you can't do server side validation until the user actually clicks a post back (or something where he sends info to the server). The best you can do is client side validation, and that requires Javascript (which I believe the ASP.NET validation controls use if you set them up to do so). Quote Gamer extraordinaire. Programmer wannabe.
Administrators PlausiblyDamp Posted June 13, 2003 Administrators Posted June 13, 2003 You could set the AutoPostBack property of the textboxes to True - but this would cause a server round trip every time you tab between textboxes. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
wyrd Posted June 13, 2003 Posted June 13, 2003 Hm.. that's a good choice. Isn't there also an option for the latest IE browsers where you can redisplay info. as if the browser didn't refresh? Quote Gamer extraordinaire. Programmer wannabe.
Netnoobie Posted June 17, 2003 Author Posted June 17, 2003 Thanks for the ideas guys. I'll poke around today and let you know what find out. Quote
Oyescat Posted June 17, 2003 Posted June 17, 2003 Strange CustomValidator You can make serverside validation with CustomValidator control, but initially, I found the same pb as you, about CustomValidator: no events fired. Finally, it works if i put : ControlToValidate="" instead of a specific control. In this way, you can use the method pointed on in OnServerValidate to test the control you want. Bur I am still interested if you make it work with a nonzero string in ControlToValidate. Here is the code I used: <asp:CustomValidator id="devisValidator" runat="server" ControlToValidate="" ErrorMessage="Estimate needed" OnServerValidate="devisValidator_ServerValidate">*</asp:CustomValidator> and the servervalidate method, with a database access : Public Sub devisValidator_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles devisValidator.ServerValidate Dim iEtat = DsEvosDetail1.Tables(0).Rows(0).Item("ETAT") If iEtat = Status.Ouverte Then If lblDevisData.Text = "" Then args.IsValid = False Else args.IsValid = True End If End If End Sub Quote
klepto Posted June 17, 2003 Posted June 17, 2003 If you want to keep the client from reloading the active page but want to retrieve data from a server, I have done it like this in the past. If the site is framed, have one frame which is of zero (0) size so it does not display. Have you custom validator call a page which retrieves your data as javascript variables or arrays into this frame. You can use this frame to store quite a bit of data and it is easily reloadable and accessable. If the site is not framed use the same process but open a new browser window off screen so the user cannot see it. In this case you should close the window as soon as your done as it is a bad look to leave these windows open when your application is finished with it. The only problem with this method is timing, you may need to have the page loading in the frame or new window call a method in the primary window when it is done. Or you can poll the frame or window for an expected variable and when it appears you know all the real data is available. It's a messy way of doing it but it makes for a clean user interface and it look realy professional. :-\ :-\ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.