Link to home
Start Free TrialLog in
Avatar of heyday2004
heyday2004

asked on

How to clear text field after the validation controls? And how can I make sure the error message will not appear in the page(just in my popup window)?

I wrote a very simple validatoin control to make sure the user provides valid zip code. Here are my problems:
1. When user can't pass the validation, there will be a pop up window, how can i clear the text field after user click the ok and return control to the text box? Because the validation is in client side, so i can't use TextBox1.Text=""; etc.

2. I added the ShowMessageBox to create a pop-up message box with the ValidationSummary control. But there is still a message in the page (same as the one in the pop up window). How can i make sure the error messages only appear in my popup window instead of appearing both in popup window and in the page? I tried to set control's Display property to none, so the in-line error message disappeared. But the summary is still in the page. Below are the code block: (add validation to TextBox1)

<asp:regularexpressionvalidator id="Regularexpressionvalidator2" Width="164px" Runat="Server" Font-Size="X-Small" Height="2px" ValidationExpression="\d{5}" ErrorMessage="Oops, you need to provide a valid FIVE DIGIT NUMBER here! Please try again." Display="none" ControlToValidate="TextBox1"></asp:regularexpressionvalidator></P>
                  
<asp:ValidationSummary Runat="server" ShowMessageBox="True" DisplayMode=SingleParagraph id="ValidationSummary1" />


Thanks a lot,
Scott

SOLUTION
Avatar of nurbek
nurbek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of heyday2004
heyday2004

ASKER

Sorry for the late reply. Thanks a lot for all the excellent answers! The second problem is solved. But the first problem is still there: How to clear the text field in client side when the user doesn't pass the regular expression validation? My button is declared as:
<asp:button id="btnEnter"  style="Z-INDEX: 101; LEFT: 720px; POSITION: absolute; TOP: 32px" runat="server"
Height="36px" Font-Bold="True" Font-Size="Small" Text="ENTER"></asp:button>

So I don't think I can add a onClick action to run the ClearWindow() Java script in above code because it is running at server?

So Rejojohny suggested put a customvalidation to combine the regular expression and clear text field. But how? I couldn't figure out the details because it was said the custom control is used in addition to the validation that that the server control can't do. So usually just add a custom validation after the regular server validation. But now, what I need is some way to trigger the clear text field action (java script) when the server validation failed. Please help. Thanks a lot again for the great answers.

-Scott
You can handle that in the ValidationControl_ServerValidate event.
HTH, Nauman.