The problem is when I click the update on the datagrid it never get to the update method. Instead , if a value is missing from the textbox it just shows the validation error... But when the user is updating the datagrid I do not care about what are in the textboxes on the top part of the page
So is there a easy way to basically say ONLY VALIDATE IF THE "ADD DATA" button is pressed..((do not validate on just ANY postback) ?You have two options. The first would be to install PetersProfessional Validation And More packet, which includes such validators. The second option is that you include the three textboxes + validators + the button inside the <asp:panel> tag. Something like this:
<asp:panel...>
your textbox
your validators
your button
</asp:panel>
<asp:datagrid...>
...
</asp:datagrid>
Now whenever the user presses the edit button in the dg: Hide the panel. You just need to set the visible property to false. Whenever the user presses the cancel button in the dg then show the panel again. Whenever the update has occured and you set the edititemindex to -1 then set also the panel again to visible. Hope that helps you.
i think ill just forget the validation controls and just make them labels that I will do validation on the server side
makes it easier
I'm assuming you have client-side validators (i.e. of the .net dynamically created JavaScript variety) Your datagrid buttons should not react with your validator because there is a property in your validator control called "ControlToValidate. You specify the control. Check to make sure you're not trying to validate everything under the sun...
There are several other ways to turn on and off validators but requires an extra postback. You would set all validators off first, then depending on what the user clicked, you can turn on those validators that pertain to what the user clicked on the server side.
A typical place u would use the above method might be
Assume X, Y and Z are textboxes and you have a formula like
X + Y = Z
You want to complain to the user if not exactly 2 items are filled out. Therefore you would disable all validators, then when user enters only value in 1 textbox or all 3, you would complain but you would be ok with exactly 2 and would calculate the missing value.
My personal opinion is that Client-Side validators are good for very client-side oriented things. The regular expression, range validators, etc. are cute, but usually incomplete.
Good luck. In my view its easier to make a panel visible/invisible than validating all controls on the server side.
No comments:
Post a Comment