Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Validation Control

Reply
Thread Tools

Validation Control

 
 
A.M
Guest
Posts: n/a
 
      01-16-2004
Hi,

I have a validation control in my page that upon any invalid data, it
disables all buttons in the page. basicly i don't have any postback in the
page if the validator finds any error.

How can have the validator just disable certain control's postback and other
part of page continue their functionality.

Thanks,
Ali


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      01-16-2004
Hi Ali,

For any buttons that should not participate in the validation, you can set
their CausesValidation property to false.

http://msdn.microsoft.com/library/de...ationTopic.asp

Is that what you meant?

Ken

"A.M" <> wrote in message
news:...
> Hi,
>
> I have a validation control in my page that upon any invalid data, it
> disables all buttons in the page. basicly i don't have any postback in the
> page if the validator finds any error.
>
> How can have the validator just disable certain control's postback and
> other
> part of page continue their functionality.
>
> Thanks,
> Ali
>
>


 
Reply With Quote
 
 
 
 
A.M
Guest
Posts: n/a
 
      01-16-2004
Thanks for reply

The problem is i have 3 buttons each button has its own controls to be
validated. So i need each Button validate it's own controls and ignore other
controls' validation

Ali



"Ken Cox [Microsoft MVP]" <> wrote in message
news:...
> Hi Ali,
>
> For any buttons that should not participate in the validation, you can set
> their CausesValidation property to false.
>
>

http://msdn.microsoft.com/library/de...ationTopic.asp
>
> Is that what you meant?
>
> Ken
>
> "A.M" <> wrote in message
> news:...
> > Hi,
> >
> > I have a validation control in my page that upon any invalid data, it
> > disables all buttons in the page. basicly i don't have any postback in

the
> > page if the validator finds any error.
> >
> > How can have the validator just disable certain control's postback and
> > other
> > part of page continue their functionality.
> >
> > Thanks,
> > Ali
> >
> >

>



 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      01-16-2004
Peter Blum sells a control that includes this feature:

"Validation groups so multiple Submit buttons only cause certain controls to
validate. "

http://www.peterblum.com/VAM/Home.aspx


"A.M" <> wrote in message
news:%...
> Thanks for reply
>
> The problem is i have 3 buttons each button has its own controls to be
> validated. So i need each Button validate it's own controls and ignore
> other
> controls' validation
>
> Ali
>
>
>
> "Ken Cox [Microsoft MVP]" <> wrote in message
> news:...
>> Hi Ali,
>>
>> For any buttons that should not participate in the validation, you can
>> set
>> their CausesValidation property to false.
>>
>>

> http://msdn.microsoft.com/library/de...ationTopic.asp
>>
>> Is that what you meant?
>>
>> Ken
>>
>> "A.M" <> wrote in message
>> news:...
>> > Hi,
>> >
>> > I have a validation control in my page that upon any invalid data, it
>> > disables all buttons in the page. basicly i don't have any postback in

> the
>> > page if the validator finds any error.
>> >
>> > How can have the validator just disable certain control's postback and
>> > other
>> > part of page continue their functionality.
>> >
>> > Thanks,
>> > Ali
>> >
>> >

>>

>
>


 
Reply With Quote
 
Alphonse Giambrone
Guest
Posts: n/a
 
      01-16-2004
Check out my post in the thread 'validating portions of asp.net page' on Jan
5.
It might be what you are looking for.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


"A.M" <> wrote in message
news:...
> Hi,
>
> I have a validation control in my page that upon any invalid data, it
> disables all buttons in the page. basicly i don't have any postback in the
> page if the validator finds any error.
>
> How can have the validator just disable certain control's postback and

other
> part of page continue their functionality.
>
> Thanks,
> Ali
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-16-2004
Hi A.M,


Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you've a ASP.NET web page which as serveral entry
fields, validator controls and also buttons on it. And you want each
button's click event(both client side and serverside?) cause only its
related validator to work rather than notify all the validators on a page.
If there is anything I misunderstood, please feel free to let me know.

First, I'd like to suggest you have a view on the tech article Alphonse
Giambrone has provided:
#ASP.NET Validation in Depth
http://msdn.microsoft.com/library/en...id.asp?frame=t
rue
This article has detailedly description the background of the ASP.NET
validation controls and the details how they work both on clientside and
serverside. I think you may get many good ideas via this articles.

As for the problem in this issue, I've do some researches based on the
above article. Here is some suggestions on it:

If clientside validation of a validator control is enabled, the ASP.NET
page will link some build in client side scripts to the page. It contains a
group of clientside APIS which control the clientside's validation
operation. Here is three important client APIS(quote from MSDN):

Name
ValidatorValidate(val):
Takes a client-validator as input. Makes the validator check its input and
update its display.

ValidatorEnable(val, enable):
Takes a client-validator and a Boolean value. Enables or disables a client
validator. Being disabled will stop it from evaluating and it will always
appear valid.

ValidatorHookupControl(control, val):
Takes an input HTML element and a client-validator. Modifies or creates the
element's change event so that it updates the validator when changed. This
can be useful for custom validators that depend on multiple input values.


What we should is just to make use of these APIs, for example the
ValidatorEnable(val, enable): can control which validator control to be
enable or not. So if we what only part of the validators to be enable when
a certain button is clicked. We can use this fuction to disable the other
validators in the certain button's onmousedown event.
For example, if we have two validators named "rfvLeft" and "rfvRight" ,when
a button is clicked, we want only "rfvLeft" to work, then we could use the
following code:

function LeftValidator()
{
ValidatorEnable(document.all('rfvLeft'), true);
ValidatorEnable(document.all('rfvRight'), false);
}

Thus, we can disable the "rfvRight" 's client validation when the button is
clicked(only rfvLeft will take validation action).
Also, it's easier to make this for server side Validation, just add the
below code in the certain button's serverside click event:
private void btnVLeft_Click(object sender, System.EventArgs e)
{

rfvLeft.Enabled = true;
rfvRight.Enabled = false;
}

To make it clearly, I've also made a simple page to show how to implement
this, the page have two textboxes, two requiredfieldvalidator and two
buttons, each button will cause only one validator to work, here is the
page and its code behind :

-----------------------------aspx page-----------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Validation</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function LeftValidator()
{
ValidatorEnable(document.all('rfvLeft'), true);
ValidatorEnable(document.all('rfvRight'), false);


}

function RightValidator()
{
ValidatorEnable(document.all('rfvLeft'), false);
ValidatorEnable(document.all('rfvRight'), true);

}


</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
<asp:TextBox id="txtLeft1" runat="server"></asp:TextBox></td>
<td>
<asp:TextBox id="txtRight1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button id="btnVLeft" runat="server" Text="Validate Left
Column"></asp:Button></td>
<td>
<asp:Button id="btnVRight" runat="server" Text="Validate Right
Column"></asp:Button></td>
</tr>
<tr>
<td>
<asp:RequiredFieldValidator id="rfvLeft" runat="server"
ErrorMessage="RequiredFieldValidator Left"
ControlToValidate="txtLeft1"></asp:RequiredFieldValidator>
</td>
<td>
<asp:RequiredFieldValidator id="rfvRight" runat="server"
ErrorMessage="RequiredFieldValidator Right"
ControlToValidate="txtRight1"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</form>
</body>
</HTML>
----------------------------------------------------------------------------
-------------

-----------------------code behind page
class-----------------------------------------
public class Validation : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtLeft1;
protected System.Web.UI.WebControls.TextBox txtRight1;
protected System.Web.UI.WebControls.Button btnVLeft;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvLeft;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvRight;
protected System.Web.UI.WebControls.Button btnVRight;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnVLeft.Attributes.Add("onmousedown","LeftValidat or()");
btnVRight.Attributes.Add("onmousedown","RightValid ator()");



}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnVLeft.Click += new System.EventHandler(this.btnVLeft_Click);
this.btnVRight.Click += new System.EventHandler(this.btnVRight_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnVLeft_Click(object sender, System.EventArgs e)
{

rfvLeft.Enabled = true;
rfvRight.Enabled = false;
}

private void btnVRight_Click(object sender, System.EventArgs e)
{
Response.Write("<br>Right Field is OK!");
rfvLeft.Enabled = false;
rfvRight.Enabled = true;
}
}

--------------------------------------------------------------------------

Please check out the preceding tech article and try out my code. If you
have any questions on it, please feel free to let me know.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
A.M
Guest
Posts: n/a
 
      01-16-2004
Thanks Steven for help.
I have tested your way, it worked.
I also tried to have 2 <form></form> tags, so validators of each form
doesn't validate the other.

It didn't work.

Am i missing something or my idea doesn't work.

Thanks,
Ali



"Steven Cheng[MSFT]" <v-> wrote in message
news...
> Hi A.M,
>
>
> Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
> assisting you on this issue.
> From your description, you've a ASP.NET web page which as serveral entry
> fields, validator controls and also buttons on it. And you want each
> button's click event(both client side and serverside?) cause only its
> related validator to work rather than notify all the validators on a page.
> If there is anything I misunderstood, please feel free to let me know.
>
> First, I'd like to suggest you have a view on the tech article Alphonse
> Giambrone has provided:
> #ASP.NET Validation in Depth
>

http://msdn.microsoft.com/library/en...id.asp?frame=t
> rue
> This article has detailedly description the background of the ASP.NET
> validation controls and the details how they work both on clientside and
> serverside. I think you may get many good ideas via this articles.
>
> As for the problem in this issue, I've do some researches based on the
> above article. Here is some suggestions on it:
>
> If clientside validation of a validator control is enabled, the ASP.NET
> page will link some build in client side scripts to the page. It contains

a
> group of clientside APIS which control the clientside's validation
> operation. Here is three important client APIS(quote from MSDN):
>
> Name
> ValidatorValidate(val):
> Takes a client-validator as input. Makes the validator check its input and
> update its display.
>
> ValidatorEnable(val, enable):
> Takes a client-validator and a Boolean value. Enables or disables a client
> validator. Being disabled will stop it from evaluating and it will always
> appear valid.
>
> ValidatorHookupControl(control, val):
> Takes an input HTML element and a client-validator. Modifies or creates

the
> element's change event so that it updates the validator when changed. This
> can be useful for custom validators that depend on multiple input values.
>
>
> What we should is just to make use of these APIs, for example the
> ValidatorEnable(val, enable): can control which validator control to be
> enable or not. So if we what only part of the validators to be enable when
> a certain button is clicked. We can use this fuction to disable the other
> validators in the certain button's onmousedown event.
> For example, if we have two validators named "rfvLeft" and "rfvRight"

,when
> a button is clicked, we want only "rfvLeft" to work, then we could use the
> following code:
>
> function LeftValidator()
> {
> ValidatorEnable(document.all('rfvLeft'), true);
> ValidatorEnable(document.all('rfvRight'), false);
> }
>
> Thus, we can disable the "rfvRight" 's client validation when the button

is
> clicked(only rfvLeft will take validation action).
> Also, it's easier to make this for server side Validation, just add the
> below code in the certain button's serverside click event:
> private void btnVLeft_Click(object sender, System.EventArgs e)
> {
>
> rfvLeft.Enabled = true;
> rfvRight.Enabled = false;
> }
>
> To make it clearly, I've also made a simple page to show how to implement
> this, the page have two textboxes, two requiredfieldvalidator and two
> buttons, each button will cause only one validator to work, here is the
> page and its code behind :
>
> -----------------------------aspx page-----------------------------------
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>Validation</title>
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> <script language="javascript">
> function LeftValidator()
> {
> ValidatorEnable(document.all('rfvLeft'), true);
> ValidatorEnable(document.all('rfvRight'), false);
>
>
> }
>
> function RightValidator()
> {
> ValidatorEnable(document.all('rfvLeft'), false);
> ValidatorEnable(document.all('rfvRight'), true);
>
> }
>
>
> </script>
> </HEAD>
> <body>
> <form id="Form1" method="post" runat="server">
> <table width="500" align="center">
> <tr>
> <td colspan="2"></td>
> </tr>
> <tr>
> <td>
> <asp:TextBox id="txtLeft1" runat="server"></asp:TextBox></td>
> <td>
> <asp:TextBox id="txtRight1" runat="server"></asp:TextBox></td>
> </tr>
> <tr>
> <td>
> <asp:Button id="btnVLeft" runat="server" Text="Validate Left
> Column"></asp:Button></td>
> <td>
> <asp:Button id="btnVRight" runat="server" Text="Validate Right
> Column"></asp:Button></td>
> </tr>
> <tr>
> <td>
> <asp:RequiredFieldValidator id="rfvLeft" runat="server"
> ErrorMessage="RequiredFieldValidator Left"
> ControlToValidate="txtLeft1"></asp:RequiredFieldValidator>
> </td>
> <td>
> <asp:RequiredFieldValidator id="rfvRight" runat="server"
> ErrorMessage="RequiredFieldValidator Right"
> ControlToValidate="txtRight1"></asp:RequiredFieldValidator>
> </td>
> </tr>
> </table>
> </form>
> </body>
> </HTML>
> --------------------------------------------------------------------------

--
> -------------
>
> -----------------------code behind page
> class-----------------------------------------
> public class Validation : System.Web.UI.Page
> {
> protected System.Web.UI.WebControls.TextBox txtLeft1;
> protected System.Web.UI.WebControls.TextBox txtRight1;
> protected System.Web.UI.WebControls.Button btnVLeft;
> protected System.Web.UI.WebControls.RequiredFieldValidator rfvLeft;
> protected System.Web.UI.WebControls.RequiredFieldValidator rfvRight;
> protected System.Web.UI.WebControls.Button btnVRight;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> btnVLeft.Attributes.Add("onmousedown","LeftValidat or()");
> btnVRight.Attributes.Add("onmousedown","RightValid ator()");
>
>
>
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.btnVLeft.Click += new System.EventHandler(this.btnVLeft_Click);
> this.btnVRight.Click += new System.EventHandler(this.btnVRight_Click);
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
>
> private void btnVLeft_Click(object sender, System.EventArgs e)
> {
>
> rfvLeft.Enabled = true;
> rfvRight.Enabled = false;
> }
>
> private void btnVRight_Click(object sender, System.EventArgs e)
> {
> Response.Write("<br>Right Field is OK!");
> rfvLeft.Enabled = false;
> rfvRight.Enabled = true;
> }
> }
>
> --------------------------------------------------------------------------
>
> Please check out the preceding tech article and try out my code. If you
> have any questions on it, please feel free to let me know.
>
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-17-2004
Hi Ali,

Thanks for your response. As for the using multi <form> tag failed
condition, I think this is also due to the mechanism of the ASP.NET
validator controls. Since in ASP.NET web page. Only one "runat=server"
<form> is allowed, all the server control or other buildin server
components or other functionalities are all based on one server form. The
validator control is the same, too. Also, as I mentioned in the last reply,
the validator controls's client validation depends on a group of client
javascript APIS, these APIS also based on the one server form(the form
which is set as "runat=server"). So if we manually add multiform to use the
validator control, there will be something incorrect with the validator
controls' internal mechanism.
Also, since the suggestion I provided in last reply (the sample page) which
use one form to contain multi validators to work separately, do you think
it appropriate to implement your question on that mode?

Also, if you do want some solution on mulit <form> tag validation, you may
look for some third party components which may provide such functionality.
And I think the link Ken Cox provided last time is a good 3th-party
validation control, you may have a look at it.:
http://www.peterblum.com/VAM/Home.aspx

If you have any questions, please feel free to post here.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)








 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Custom validation on a control in a user control.(asp.net 2.0) Jens Jensen ASP .Net 0 07-07-2006 09:46 AM
PasswordRecovery control trips Login control's validation The Colonel ASP .Net 1 07-06-2006 09:18 PM
Using Summary Validation control with server Custom validation =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= ASP .Net 2 10-15-2004 06:15 PM
Displaying a Validation Error in a Validation Summary Control Lucas Tam ASP .Net 2 02-26-2004 07:49 PM
Re: only custom validation control does server side validation? Colin Mackay ASP .Net 0 06-25-2003 07:54 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57