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:regularexpressionvali dator id="Regularexpressionvalid ator2" 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="TextBox 1"></asp:r egularexpr essionvali dator></P>
<asp:ValidationSummary Runat="server" ShowMessageBox="True" DisplayMode=SingleParagrap h id="ValidationSummary1" />
Thanks a lot,
Scott
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:regularexpressionvali
<asp:ValidationSummary Runat="server" ShowMessageBox="True" DisplayMode=SingleParagrap
Thanks a lot,
Scott
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can handle that in the ValidationControl_ServerVa lidate event.
HTH, Nauman.
HTH, Nauman.
ASKER
<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