PC Review


Reply
Thread Tools Rate Thread

Client-side validation of controls

 
 
=?Utf-8?B?QWxCcnVBbg==?=
Guest
Posts: n/a
 
      27th May 2007
Hi all,

I have a situation in which I need to verify that either of two textboxes
contain an entry; I'm initially uninterested in whether or not the entries
are valid, only that there is at least one entry. The validity of the entry
will be checked when I first post back the data to the server, but I don't
want to perform a postback if both textboxes are empty.

My initial thought is to write a simple javascript function to return true
if there's an entry in either box or return false if both boxes are empty. I
could then call this function from another javascript function that would
intercept the onclick event for my form's pushbutton. The problem I'm
encountering is I can't get a javascript function to work for the button's
onclick event. I created a function called ButtonClicked and have it wired
up the the button's onclick event by stating 'onclick="ButtonClicked"' in the
html code for the pushbutton, but I don't know where or how to obtain the
Object and the EventArgs my code-behind handler expects for the pushbutton.

Does anyone have a brief example or can anyone point me where I can find one?

Thanks!
 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      27th May 2007
"AlBruAn" <(E-Mail Removed).(donotspam)> wrote in message
news:7462466F-11D6-476C-8F69-(E-Mail Removed)...

> Does anyone have a brief example or can anyone point me where I can find
> one?


<script type="text/javascript">
function validateForm()
{
if
(document.getElementById('<%=txtTextBox1.ClientID%>').value.length == 0
&& document.getElementById('<%=txtTextBox2.ClientID%>').value.length
== 0)
{
alert('Both textboxes cannot be blank');
return false;
}
}
</script>

<form id="frmDefault" runat="server">
<asp:TextBox ID="txtTextBox1" runat="server" /><br />
<asp:TextBox ID="txtTextBox2" runat="server" /><br />
<asp:Button ID="cmdSave" runat="server" Text="Save"
OnClick="cmdSave_Click" OnClientClick="return validateForm();" />
</form>


--
http://www.markrae.net

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Client-side validation of user controls in asp.net 1.1 urig Microsoft ASP .NET 0 16th Nov 2006 04:48 PM
ASP.net validation controls don't are not validated(fired) on the client side. mallik Microsoft ASP .NET 3 7th Jul 2005 09:42 AM
Asp.net Client Side Validation Controls are not workiing in Non IE Browsers msnews.microsoft.com Microsoft ASP .NET 1 22nd Feb 2005 08:57 AM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt Microsoft ASP .NET 14 30th Jan 2004 09:15 AM
Client Side Validation Controls Gareth Microsoft ASP .NET 3 12th Nov 2003 03:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:27 PM.