Thanks for the reply Tian.
I built a project as you suggested except I added a submit button to each
user control and have the same problem.
Here is what I did:
In a new VSN2002 project
Project > Add Web User Control
WebUserControl1.ascx
==================================
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="WebUserControl1.ascx.vb" Inherits="Validator.WebUserControl1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<P>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ErrorMessage="Entry Required"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator></P>
<P>
<asp:Button id="Button1" runat="server" Text="Submit 1"></asp:Button></P>
======================================
codebehind: WebUserControl1.ascx.vb
====================================
Public MustInherit Class WebUserControl1
Inherits System.Web.UI.UserControl
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
End Class
================================================== ===================
Created a second control identical to the first (except that I labeled the
submit button as Submit 2) and named it WebUserControl2.
================================================== ==
On the default Webform1.aspx I added the 2 controls.
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="Validator.WebForm1"%>
<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="WebUserControl1.ascx" %>
<%@ Register TagPrefix="uc1" TagName="WebUserControl2"
Src="WebUserControl2.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<uc1:WebUserControl1 id="WebUserControl11"
runat="server"></uc1:WebUserControl1></P>
<P>
<uc1:WebUserControl2 id="WebUserControl21"
runat="server"></uc1:WebUserControl2></P>
</form>
</body>
</HTML>
================================
CodeBehind:
================================
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
End Class
================================================== =========
When I view the form in a browser, I then see 2 text boxes and 2 submit
buttons.
If I make an entry in the first textbox and click 'Submit1', the
requiredfield validator for the second textbox displays its message and the
form is not submitted.
The only way to submit the form is to make an entry in both textboxes.
I would like to be able to click 'Submit 1' and only require the first
textbox to have an entry or click 'Submit 2' and only require the second
text box to have an entry.
I guess what is happening makes sense since the rendered html contains only
one form and the validators' validation is required for the form to be
submitted.
It seems that there should be a way around this.
==========================
As for item 2, when you say 'declare OleDbConnection as public member", am I
correct in assuming that you mean in the parent form?
How then does one pass it to (or reference it in) the user controls?
--
Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:vN**************@cpmsftngxa07.phx.gbl...
Hello Alphonse,
Thanks for your post. I now share the following inforamtion with you:
1. How can I get the validators for each control to only function for their particular control?
As you know, a RequiredFieldValidator should be bound to a designated
control and other controls will not affect it. I created a sample and it
works properly (does not reproduce the problem you are facing). Here is
what I did:
a. Create a Web app.
b. Add two Web Forms containing a Edit box and a RequiredFieldValidator
(set ControlToValidate properly) respectively.
c. Converting the Web Forms page to user controls per MSDN article below:
http://msdn.microsoft.com/library/de...us/vbcon/html/ vbwlkwalkthroughconvertingwebformtousercontrol.asp
d. Add a new Web Forms page containing two user controls, and
RequiredFieldValidators work as expected.
Please check it on your side. If the problem persists, could you post a
reproducible project?
2. What is the best way to share an oledb connection between the 2
controls, so each one does not open a new connection?
You can declare OleDbConnection as public member and pass it to your user
controls.
Please feel free to let me know if you have any problems or concerns.
Have a nice day!
Regards,
HuangTM
Microsoft Online Partner Support
MCSE/MCSD
Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.