Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with web user control

73 views
Skip to first unread message

SatinderGT

unread,
Feb 28, 2003, 7:31:48 AM2/28/03
to
Dear Group,

I have created a Web User Control (.ascx). I can drag that on the page. Now,
i wanted to know few things:

1. When i drag-drop the validator control on the page, in the
controltovalidate property i cannot see the name of my custom control
(.ascx). what could be the reason ??

2. I want that the java script that is attached in the custom control must
be posted only once when i say view source from IE.

How do i achieve the above two features ??


thanks in advance,


sat.


Marina

unread,
Feb 28, 2003, 8:52:10 AM2/28/03
to
A validator cannot validate a user control - this has no meaning. It can
validate certain types of web controls: textboxes, dropdowns, etc. What
would it mean to validate your user control? Your user control could have 10
textboxes and 18 dropdowns - what is the validator supposed to do?

For question 2, call the RegisterClientScriptBlock method of the page class
to make sure that a script with the same key is written out only once.

"SatinderGT" <sati...@thegt.com> wrote in message
news:OmZ2Ryy3...@TK2MSFTNGP10.phx.gbl...

Saverio Mercurio

unread,
Feb 28, 2003, 10:46:57 AM2/28/03
to
Actually, it is possible for a validator to validate a user control. The
caveat, obviously, is that you need to know the name of the specific control
inside the user control that you want to validate. I wrote a user control
that is a date input with a popup calendar. The user control has a built-in
validator to check that the date entered is a valid date. When I use two
instances of this control, like when I need to enter a start date and an end
date, I put a compare validator on the form that has the two
DateWithCalendar controls to check that the end date is after the start
date. In the compare validator's ControlToValidate property I enter
"ctlEndDate:txtDate", where "ctlEndDate" is the name I gave to the end date
user control and "txtDate" is the name of the textbox that's within the user
control. For the "ControlToCompare" you use "ctlStartDate:txtDate".

As for the original question, you can probably use this technique to
"validate" the user control.

--
Saverio Mercurio
mailto:Saverio.M**erc...@atNOgroupSPAMinc.com
NOTE: My email address has been purposefully altered to thwart mailing list
harvesters.


"Marina" <zlat...@nospam.hotmail.com> wrote in message
news:eN8QYCz3...@TK2MSFTNGP11.phx.gbl...

Marina

unread,
Feb 28, 2003, 4:05:10 PM2/28/03
to
I read the post to mean 'validate the entire control'. Not validate a
control within the user control.

"Saverio Mercurio" <Saverio.M**erc...@atNOgroupSPAMinc.com> wrote in
message news:uHhpNC03...@TK2MSFTNGP09.phx.gbl...

Chris Koenig

unread,
Mar 1, 2003, 10:33:23 PM3/1/03
to
How about this:

<url>
ms-
help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWebUIValidationPropertyAtt
ributeClassTopic.htm
</url>

This article describes the ValidationPropertyAttribute attribute with
which you indicate which property on the user control should be used for
validation. According to the help, the validators will use this property
as their required field, comparison field, or whatever:

[ValidationPropertyAttribute("CustomProperty")]
public abstract class UserControl1: System.Web.UI.UserControl
{
private string m_Value = String.Empty;
public string MyProperty
{
get { return m_Value; }
set { m_Value = value; }
}
}

HTH!
Chris

"Marina" <zlat...@nospam.hotmail.com> wrote in
news:e$umW023C...@TK2MSFTNGP09.phx.gbl:

Satinderpal Singh

unread,
Mar 3, 2003, 12:10:44 AM3/3/03
to
It works - UserControl1:txtDate.

Thanks a ton.

Does any one has example on the javascript question. That is if there
are 2 instances of the control on one .aspx, how can i have the java
script for only once.


thanks in advance,

sat.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Satinderpal Singh

unread,
Mar 3, 2003, 4:50:58 AM3/3/03
to
Hello ALL (my second mail),

First of all thanks for your help.

Can you all please help me with making the date control (.ascx) using
ASP.NET. As i am new to .net, i m facing lot of problems.

Like see, in my function i have to pass the name of my control in
javascript, like UserControl1:txtDate, but if there are 2 controls on
one page, do i need two different functions, coz the instance of control
2 would be UserControl2:txtDate ??? or is there a way to directly refer
txtDate in the javascript, that is written in the user control (.ascx).

Your help in the above matter would be highly appreciated.

waiting for your reply.

thanks in advance

satinder.

Chris Koenig

unread,
Mar 3, 2003, 10:12:24 AM3/3/03
to
Look into the Page.Render* script methods. These are cool because you
can check to see if a script is already rendered by a key you assign it
before rewriting it.


Here's a few interesting articles from MSDN

<url>
http://search.microsoft.com/gomsuri.asp?n=1&c=rp_Results&siteid=us/dev&ta
rget=http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIP
ageClassRegisterClientScriptBlockTopic.asp </url>

<url>
http://search.microsoft.com/gomsuri.asp?n=3&c=rp_Results&siteid=us/dev&ta
rget=http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIP
ageClassIsClientScriptBlockRegisteredTopic.asp </url>


HTH!
Chris

Satinderpal Singh <sati...@thegt.com> wrote in
news:eAwLlpW4...@TK2MSFTNGP10.phx.gbl:

0 new messages