473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Client-side validation on user control

I cannot get a web user control to validation client-side using a required
field validator. It only validates server side.

I have a web user control in .net 2.0. I have a single text box on it. I
have a public Text property defined below:

<ValidationProperty("Text")> _
Partial Class MyWebUserControl
Inherits System.Web.UI.UserControl

Public Property Text() As String
Get
Return TextBox1.Text
End Get
Set(ByVal value As String)
TextBox1.Text = value
End Set
End Property

End Class

I have a RequiredFieldValidator on the same web page as my user control. I
put the user control's id in the ControlToValidate property of the validator
(please note that I must type it in, it doesn't show up in the dropdown list).

The control validates only server-side, not client-side. The html source
for my page contains the following:

<div>
<input name="MyWebUserControl1$TextBox1" type="text"
id="MyWebUserControl1_TextBox1" />

<span id="RequiredFieldValidator1" style="color:Red;">The user
control text is required.</span
</div>
....
<script type="text/javascript">
<!--
var RequiredFieldValidator1 = document.all ?
document.all["RequiredFieldValidator1"] :
document.getElementById("RequiredFieldValidator1") ;
RequiredFieldValidator1.controltovalidate = "MyWebUserControl1";
RequiredFieldValidator1.errormessage = "The user control text is required.";
RequiredFieldValidator1.isvalid = "False";
RequiredFieldValidator1.evaluationfunction =
"RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator1.initialvalue = "";
// -->
</script>

Notice that the id for the control is "MyWebUserControl1_TextBox1" and the
javascript is just calling it "MyWebUserControl1". I'm not sure if this is a
problem or not.

Any suggestions? --David
May 10 '06 #1
3 8899

RequiredFieldValidator1.controltovalidate = TextBox1.ClientID() or
"MyWebUserControl1_TextBox1";

"David Davis" <Da********@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
I cannot get a web user control to validation client-side using a required
field validator. It only validates server side.

I have a web user control in .net 2.0. I have a single text box on it. I
have a public Text property defined below:

<ValidationProperty("Text")> _
Partial Class MyWebUserControl
Inherits System.Web.UI.UserControl

Public Property Text() As String
Get
Return TextBox1.Text
End Get
Set(ByVal value As String)
TextBox1.Text = value
End Set
End Property

End Class

I have a RequiredFieldValidator on the same web page as my user control.
I
put the user control's id in the ControlToValidate property of the
validator
(please note that I must type it in, it doesn't show up in the dropdown
list).

The control validates only server-side, not client-side. The html source
for my page contains the following:

<div>
<input name="MyWebUserControl1$TextBox1" type="text"
id="MyWebUserControl1_TextBox1" />

<span id="RequiredFieldValidator1" style="color:Red;">The user
control text is required.</span
</div>
...
<script type="text/javascript">
<!--
var RequiredFieldValidator1 = document.all ?
document.all["RequiredFieldValidator1"] :
document.getElementById("RequiredFieldValidator1") ;
RequiredFieldValidator1.controltovalidate = "MyWebUserControl1";
RequiredFieldValidator1.errormessage = "The user control text is
required.";
RequiredFieldValidator1.isvalid = "False";
RequiredFieldValidator1.evaluationfunction =
"RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator1.initialvalue = "";
// -->
</script>

Notice that the id for the control is "MyWebUserControl1_TextBox1" and the
javascript is just calling it "MyWebUserControl1". I'm not sure if this
is a
problem or not.

Any suggestions? --David

May 10 '06 #2
I tried this already and I get a "Unable to find control id
'WebUserControl1_TextBox1' referenced by the 'ControlToValidate' property of
'RequiredFieldValidator1'" error, even when I expose the textbox in my user
control as a property.

"MSDN" wrote:

RequiredFieldValidator1.controltovalidate = TextBox1.ClientID() or
"MyWebUserControl1_TextBox1";

"David Davis" <Da********@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
I cannot get a web user control to validation client-side using a required
field validator. It only validates server side.

I have a web user control in .net 2.0. I have a single text box on it. I
have a public Text property defined below:

<ValidationProperty("Text")> _
Partial Class MyWebUserControl
Inherits System.Web.UI.UserControl

Public Property Text() As String
Get
Return TextBox1.Text
End Get
Set(ByVal value As String)
TextBox1.Text = value
End Set
End Property

End Class

I have a RequiredFieldValidator on the same web page as my user control.
I
put the user control's id in the ControlToValidate property of the
validator
(please note that I must type it in, it doesn't show up in the dropdown
list).

The control validates only server-side, not client-side. The html source
for my page contains the following:

<div>
<input name="MyWebUserControl1$TextBox1" type="text"
id="MyWebUserControl1_TextBox1" />

<span id="RequiredFieldValidator1" style="color:Red;">The user
control text is required.</span
</div>
...
<script type="text/javascript">
<!--
var RequiredFieldValidator1 = document.all ?
document.all["RequiredFieldValidator1"] :
document.getElementById("RequiredFieldValidator1") ;
RequiredFieldValidator1.controltovalidate = "MyWebUserControl1";
RequiredFieldValidator1.errormessage = "The user control text is
required.";
RequiredFieldValidator1.isvalid = "False";
RequiredFieldValidator1.evaluationfunction =
"RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator1.initialvalue = "";
// -->
</script>

Notice that the id for the control is "MyWebUserControl1_TextBox1" and the
javascript is just calling it "MyWebUserControl1". I'm not sure if this
is a
problem or not.

Any suggestions? --David


May 10 '06 #3
Hi,
You can solve the problem by setting the name property for the textbox and
then using document.getelementbyname function in JavaScript should be able
to get the control into some variable. Once you get hold of the control on
the client-side then application of any validation function shouldn't
present you any problem.

Regards
Parag Kulkarni
MTS
Persistent Systems Private Limited


"David Davis" <Da********@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
I tried this already and I get a "Unable to find control id
'WebUserControl1_TextBox1' referenced by the 'ControlToValidate' property
of
'RequiredFieldValidator1'" error, even when I expose the textbox in my
user
control as a property.

"MSDN" wrote:

RequiredFieldValidator1.controltovalidate = TextBox1.ClientID() or
"MyWebUserControl1_TextBox1";

"David Davis" <Da********@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
>I cannot get a web user control to validation client-side using a
>required
> field validator. It only validates server side.
>
> I have a web user control in .net 2.0. I have a single text box on it.
> I
> have a public Text property defined below:
>
> <ValidationProperty("Text")> _
> Partial Class MyWebUserControl
> Inherits System.Web.UI.UserControl
>
> Public Property Text() As String
> Get
> Return TextBox1.Text
> End Get
> Set(ByVal value As String)
> TextBox1.Text = value
> End Set
> End Property
>
> End Class
>
> I have a RequiredFieldValidator on the same web page as my user
> control.
> I
> put the user control's id in the ControlToValidate property of the
> validator
> (please note that I must type it in, it doesn't show up in the dropdown
> list).
>
> The control validates only server-side, not client-side. The html
> source
> for my page contains the following:
>
> <div>
> <input name="MyWebUserControl1$TextBox1" type="text"
> id="MyWebUserControl1_TextBox1" />
>
> <span id="RequiredFieldValidator1" style="color:Red;">The user
> control text is required.</span
> </div>
> ...
> <script type="text/javascript">
> <!--
> var RequiredFieldValidator1 = document.all ?
> document.all["RequiredFieldValidator1"] :
> document.getElementById("RequiredFieldValidator1") ;
> RequiredFieldValidator1.controltovalidate = "MyWebUserControl1";
> RequiredFieldValidator1.errormessage = "The user control text is
> required.";
> RequiredFieldValidator1.isvalid = "False";
> RequiredFieldValidator1.evaluationfunction =
> "RequiredFieldValidatorEvaluateIsValid";
> RequiredFieldValidator1.initialvalue = "";
> // -->
> </script>
>
> Notice that the id for the control is "MyWebUserControl1_TextBox1" and
> the
> javascript is just calling it "MyWebUserControl1". I'm not sure if
> this
> is a
> problem or not.
>
> Any suggestions? --David


May 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news.microsoft.com | last post by:
Hi I write dll library which one of it component will be Net socket communication. Communication is working very good, but i've got problem when client is connecting. When server is started,...
0
by: Tim Northrup | last post by:
Help! We have DB2 V7.2 (fixpak 12) installed on Windows2003 Server, and the latest V7.2 client installed on another system. The DB2CODEPAGE on all systems is set to 1208, and the database was...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
0
by: Harley | last post by:
Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and...
2
by: Delmar | last post by:
I need to build Web Application that will generate a client to execute some operations. Each client has running silent application. Maybe somebody can advice me what can I do ? Thank you.
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
5
by: Yossarian | last post by:
I have a handheld running CE .NET 4.2 and I am using c# with framework 1.1 to develop a solution for syncing data that is on the handheld with the local pc. Our handheld cradles only support...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
4
MMcCarthy
by: MMcCarthy | last post by:
http://bytes.com/images/howtos/projectscope_blocks.jpgAs a freelance IT consultant for over 10 years, I’ve come to appreciate well defined project scopes. A project scope is a common understanding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.