Validation Problem

cardingpower

New Member
Can anyone tell me how I would be able to validate separate text boxes for different properties depending on what control button is pressed? <BR><BR>For Example I would like to only validate textbox1 if the Delete button is pressed, and textbox2 if the save button is press?<BR><BR>Thanks in advance.Writing different event handlers for each button. That is, when the Delete button would specify to call the DeleteBtnClick event handler for the OnClick event, and the Save button would call the SaveBtnClick. Next, create validation controls for the two textboxes and call these TextBox1Valid, TextBox2Valid. Now, let's say that when the delete button is clicked you want to make sure that TextBox1 is valid, that is that the TextBox1Valid validation control's IsValid property returns true. You can do:<BR><BR>Sub DeleteBtnClick(sender as Object, e as EventArgs)<BR> If TextBox1Valid.IsValid then<BR> 'Do whatever.<BR> Else<BR> 'Display the error<BR> End If<BR>End Sub<BR><BR>You'll want to set TextBox1Valid and TextBox2Valid's Display property to None intially, and then, where I have<BR><BR>'Display the Error<BR><BR>you'll want to set the appropriate validation control's Display property to dynamic or static or whatever. (See the docs for more info.)<BR><BR>Also realize that I don't have the docs in front of me right now, so I can't ensure that the above will work 100%, but it is the approach you will likely want to take. hthI have tried this and I am still running into the problem of having the validators run for both of the buttons. If I press on the Save button the Delete validation still kicks in. Is there a way to bypass the validation totally until it is called in the aspx.vb code?Thank you, I'll give that a try.Did you set BOTH validators's Display to None intially?<BR><BR><asp:RequiredFieldValidator ... Display="None" /><BR><BR>Are you checking Page.IsValid anywhere? Don't, just use the .IsValid property of the validation control itself. Make sense?
 
Back
Top