Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi!

 

I have a litte problem with my CustomValidator.

 

 

What my CustomValidator should do:

The CustomValidator should check if 2 textboxes are empty..

if yes he should diplay a message.

 

 

This is my code:

 

<asp:customvalidator id="CustomValidator1" runat="server" ErrorMessage="Sie müssen min. 1 Telefonnummer angeben"
	Display="Static" OnServerValidate="ValidateExistanceOfPhones"></asp:customvalidator></P>

 

 

<script runat="server">
	void ValidateExistanceOfPhones(object source, ServerValidateEventArgs args)
	{
		args.IsValid = !((m_txtTelephoneNumber.Text.Length == 0) && (m_txtMobileNumber.Text.Length == 0));
	}
</script>

 

 

 

the calidator check ValidateExistanceOfPhones. but when args.IsValid = false the message isn't

shown. What is the problem??!

Make I something wrong?

 

2. quastion: is it possible to check the state of the 2 textboxes on the client side?

when YES how?

 

 

 

best regards,

 

 

gicio

Posted

to check on the clientside you have to use javascript.

 

add this block before the </head> tag

<script language="javascript">
function jsCheckTextBoxes()
{
    if (document.forms[0].TextBox1.value == "" || document.forms[0].TextBox2.value == "")
    {
         alert("Bitte beide TextBoxen ausfüllen");
         return false;
    }
    else
    {
         return true;
    }
}
</script>

 

now you have to code when this function should be fired.

for any <asp:button> write in your code-behind file following (i do it in pageload of server-code)

 

Button1.Attributes.Add("onclick", "return jsCheckTextBoxes();");

 

if the function return true, your asp-button submits the page. if it return false, no submit will be done!

 

regards!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...