I have an editable DataList with several text boxes, a "Save" button and a "Cancel" button in the EditItemTemplate.
My cancel button's handler is:
DataList1.EditItemIndex = -1
GetData() 'sub to get data for list
When I add Required Field Validators to the text boxes, the Cancel command will no longer work. If I enter a value for the required fields, then the Cancel button will work properly.
What needs to be done to override the validators to return the DataList to its normal state?
TIA,
Brandon
Ok, I got this fixed by setting the Causes Validation property of the cancel button to false, but I'm having another issue...
I can't get custom validation subs to find the values of controls.
Let's say I have a text box in an edit item template. If I say:
Protected Sub ValidateZipCode(ByVal source As Object, ByVal args as ServerValidateEventArgs)
Dim tbxZip as new TextBox = CType(Page.FindControl("tbxZip"),TextBox)
End Sub
tbxZip can't find the control specified in the Page.FindControl. What am I doing wrong?
TIA,
Brandon
Go the the HTML view of grid and check the cancel link button and see in the properties window if there is a 'CausesValidation' attribute, if there is one, set it to false, if not, you may have to try validating another way, perhaps using javascript.
I got everything working. I forgot that I could add my own handlers.
So, I put my custom validator into it's own sub as such:
Protected Sub DoSomeValidation(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
'do something here
End Sub
Then, in the DataList's ItemDataBound : EditItem, I add the handler to the control when the data is bound as such:
Dim cvYourValidator As CustomValidator = CType(e.Item.FindControl("cvTheValidator"), CustomValidator)
AddHandler cvYourValidator .ServerValidate, AddressOf Me.DoSomeValidation
Hope this helps someone,
Brandon
No comments:
Post a Comment