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

heyday2004Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nurbekCommented:
in your popup page
you can use javascript

<SCRIPT LANGUAGE=javascript>
function CloseWindow()
{
  window.opener.myFormName.myField.value = "";
  window.close;
}
</SCRIPT>

 <input type="button" name="Button" value="Close" onClick="CloseWindow();">
0
nauman_ahmedCommented:
Usually I do it in the following way:

<asp:requiredfieldvalidator id="rfvTxtName" runat="server" ControlToValidate="TxtName" Display="None"
                                                ErrorMessage="Name"></asp:requiredfieldvalidator>

<asp:validationsummary id="VSUserForm" runat="server" Font-Names="Verdana" Width="440px" Font-Size="XX-Small"
                                          ShowSummary="False" ShowMessageBox="True" HeaderText="Please provide information for the following required field(s): <br />--------------------------------------------------------------------"
                                          Font-Bold="True"></asp:validationsummary>


This will display the javascript popup containing any validation error. Also its a good idea to re-validate the page when the user select submit as javascript being disabled will not show anything at all in the above code:

private void btnSubmit_Click(object Sender, EventArgs e)
{
  Page.Validate();
  if (!Page.IsValid)
  {
     this.VSUserForm.ShowSummary = true;
  }
}

HTH,Nauman.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RejojohnyCommented:
>>I wrote a very simple validatoin control to make sure the user provides valid zip code.
1. add another customValidator control and set the property
ClientValidationFunction = myvalidation
.. within this client-side function .. do ur validation and then set the control as blank using
<script language=javascript>
function myvalidation()
{
//use regex to validate ur control.. if validation fails then
document.getElementById("urcontrol").value = '';
}
2. set the "ShowSummary" to "False" for the ValidationSummary control
0
heyday2004Author Commented:
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
0
nauman_ahmedCommented:
You can handle that in the ValidationControl_ServerValidate event.
HTH, Nauman.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.