|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sharing a ValidatorI have a form that contains a number of fields, all of which have
validators. There are two submit buttons, one to update a record and one to add a record. Because the only difference in validation is to make sure someone is not using a username that is already in use, I would like to be able to use all the other validators for both the add and update buttons. However, because as far as I know a validator can only be in one validationgroup, that does not help me (although if they haven't already, I think it would be a great improvement for the next version of the .NET framework). Does anybody have any suggestions on a good way to solve my problem (having 2 copies of each validator would work and be very simple, but I would hope for a more efficient way)? Thanks. Why not use only one button? Change the text of the button from "Add" to
"Update" depending on the data that is populating your form. Use a hidden textbox to keep the ID of the item. So if the textbox has a ID >0 then it's an update, else it's an Add. It's a little more complex than that, but it might get you started.Show quoteHide quote "Nathan Sokalski" <njsokal***@hotmail.com> wrote in message news:eQCewiZHIHA.3940@TK2MSFTNGP05.phx.gbl... >I have a form that contains a number of fields, all of which have >validators. There are two submit buttons, one to update a record and one to >add a record. Because the only difference in validation is to make sure >someone is not using a username that is already in use, I would like to be >able to use all the other validators for both the add and update buttons. >However, because as far as I know a validator can only be in one >validationgroup, that does not help me (although if they haven't already, I >think it would be a great improvement for the next version of the .NET >framework). Does anybody have any suggestions on a good way to solve my >problem (having 2 copies of each validator would work and be very simple, >but I would hope for a more efficient way)? Thanks. > -- > Nathan Sokalski > njsokal***@hotmail.com > http://www.nathansokalski.com/ > I would do that, but unfortunately the client wants to always see both the
Add and Update buttons. If I were designing what the page should look like, I would probably do something similar to your suggestion. But unfortunately, an unhappy client means an unhappy boss which means an unhappy paycheck. I guess that's all part of the business, with people caring so much about the look of the page. Show quoteHide quote "ace_away" <a**@away.com> wrote in message news:uSWs3h%23HIHA.5764@TK2MSFTNGP06.phx.gbl... > Why not use only one button? Change the text of the button from "Add" to > "Update" depending on the data that is populating your form. > > Use a hidden textbox to keep the ID of the item. So if the textbox has a > ID > >0 then it's an update, else it's an Add. > > It's a little more complex than that, but it might get you started. > > > > "Nathan Sokalski" <njsokal***@hotmail.com> wrote in message > news:eQCewiZHIHA.3940@TK2MSFTNGP05.phx.gbl... >>I have a form that contains a number of fields, all of which have >>validators. There are two submit buttons, one to update a record and one >>to add a record. Because the only difference in validation is to make sure >>someone is not using a username that is already in use, I would like to be >>able to use all the other validators for both the add and update buttons. >>However, because as far as I know a validator can only be in one >>validationgroup, that does not help me (although if they haven't already, >>I think it would be a great improvement for the next version of the .NET >>framework). Does anybody have any suggestions on a good way to solve my >>problem (having 2 copies of each validator would work and be very simple, >>but I would hope for a more efficient way)? Thanks. >> -- >> Nathan Sokalski >> njsokal***@hotmail.com >> http://www.nathansokalski.com/ >> > > Hi, Nathan
The validators work regardless the button pressed, however, you can define the ValidationGroup for the button and that button would validate only with the specified validation group (or validators that does not have the ValidationGroup specified)... well, at least according to the docs -- I didn't make any test with it so far. Regards, Paulo Santos http://pjondevelopment.50webs.com Show quoteHide quote On Nov 2, 6:38 pm, "Nathan Sokalski" <njsokal***@hotmail.com> wrote: > I have a form that contains a number of fields, all of which have > validators. There are two submit buttons, one to update a record and one to > add a record. Because the only difference in validation is to make sure > someone is not using a username that is already in use, I would like to be > able to use all the other validators for both the add and update buttons. > However, because as far as I know a validator can only be in one > validationgroup, that does not help me (although if they haven't already, I > think it would be a great improvement for the next version of the .NET > framework). Does anybody have any suggestions on a good way to solve my > problem (having 2 copies of each validator would work and be very simple, > but I would hope for a more efficient way)? Thanks. > -- > Nathan Sokalski > njsokal...@hotmail.comhttp://www.nathansokalski.com/
localized asp:label w/nested control bug?
Paint in ASP.NET Script Control.value method Intercepting DropDownList Selected Value when not in list of Items OnServerValidate handler - how to know which CustomValidator is using it ? use index on dropdownlist Help with vb.net Maths syntax in asp.net Menu Control used on a MasterPage Bind images to a data list Async Upload Control |
|||||||||||||||||||||||