DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 06 Jun 2007 19:20:28 -0700,    posted on: microsoft.public.dotnet.framework.aspnet.buildingcontrols        back       

Thread Index
  1    daokfella
          2    Teemu Keiski


Possible to validate between INamingContainers in 2.0?   
I have a composite control that contains a texbox and comparevalidator
(and other stuff not applicable to this post). Right now, it does a
simple DataTypeCheck or any comparison to the ValueToCompare property.
I've exposed the ValueToCompare and the CompareOperator properties.
The control is for a date, so the Type property is permanently set as
Date.

I'd like to expose the ControlToCompare property, but it won't work
because I'll always get the "Cannot find the control referenced by the
ControlToCompare property (paraphrased)". I'm assuming this is because
the two compared controls are in different INamingContainers.

Has anybody found a workaround? I'd like for my custom controls to be
able to be compared against each other. My short term workaround is
allowing for the internal compare operator to be disabled, and then
just using new comparevalidators on the page between the two controls.

Also, when setting the ValidationCompare attribute in my custom
control, this control id is shown in the dropdown for another's
ControlToCompare property.  Unfortunately, this is the id of the top
level <span> container and not the textbox within the
compositecontrol. I thought that was the problem, but even after
exposing the textbox ClientId and using that as the ControlToCompare,
it still didn't work.

Thanks,

Jason
Date:Wed, 06 Jun 2007 19:20:28 -0700   Author:  

Re: Possible to validate between INamingContainers in 2.0?   
It should be if you assign UniqueID to the ControlToValidate property. As 
validator uses FindControl to locate the control to be validated, it can 
find it on other naming containers if the given id is unique id (exposing 
the full containment hierarchy of the control)

Assuming I have a user control, WebUserConntrol1.ascx and it's code-behind

<%@ Control Language="vb" AutoEventWireup="false" 
CodeBehind="WebUserControl1.ascx.vb" 
Inherits="CSTestApplication1.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

Public Partial Class WebUserControl1
    Inherits System.Web.UI.UserControl

    Public ReadOnly Property TheBox() As TextBox
        Get
            Return TextBox1
        End Get
    End Property

End Class

And using it on aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" 
Inherits="CSTestApplication1.WebForm1" %>
<%@ Register Src="WebUserControl1.ascx" TagName="WebUserControl1" 
TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
runat="server" 
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
        <uc1:WebUserControl1 ID="UC1" runat="server" />
    </div>
    </form>
</body>
</html>

And relevant code to set the UNiqueID

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles Me.Load
        Me.RequiredFieldValidator1.ControlToValidate = 
Me.UC1.TheBox.UniqueID
    End Sub


-- 
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"daokfella"  wrote in message 
news:1181182828.956812.189930@g4g2000hsf.googlegroups.com...

>I have a composite control that contains a texbox and comparevalidator
> (and other stuff not applicable to this post). Right now, it does a
> simple DataTypeCheck or any comparison to the ValueToCompare property.
> I've exposed the ValueToCompare and the CompareOperator properties.
> The control is for a date, so the Type property is permanently set as
> Date.
>
> I'd like to expose the ControlToCompare property, but it won't work
> because I'll always get the "Cannot find the control referenced by the
> ControlToCompare property (paraphrased)". I'm assuming this is because
> the two compared controls are in different INamingContainers.
>
> Has anybody found a workaround? I'd like for my custom controls to be
> able to be compared against each other. My short term workaround is
> allowing for the internal compare operator to be disabled, and then
> just using new comparevalidators on the page between the two controls.
>
> Also, when setting the ValidationCompare attribute in my custom
> control, this control id is shown in the dropdown for another's
> ControlToCompare property.  Unfortunately, this is the id of the top
> level <span> container and not the textbox within the
> compositecontrol. I thought that was the problem, but even after
> exposing the textbox ClientId and using that as the ControlToCompare,
> it still didn't work.
>
> Thanks,
>
> Jason
> 
Date:Wed, 13 Jun 2007 20:53:06 +0300   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us