473,473 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validation Control

A.M
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
Nov 18 '05 #1
7 2858
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" <IH*******@sapm123.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #2
A.M
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]" <BA************@sympatico.ca> wrote in message
news:Oy**************@TK2MSFTNGP11.phx.gbl...
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" <IH*******@sapm123.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #3
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" <IH*******@sapm123.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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]" <BA************@sympatico.ca> wrote in message
news:Oy**************@TK2MSFTNGP11.phx.gbl...
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" <IH*******@sapm123.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
> 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
>
>



Nov 18 '05 #4
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" <IH*******@sapm123.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #5
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.)

Nov 18 '05 #6
A.M
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-******@online.microsoft.com> wrote in message
news:ol**************@cpmsftngxa08.phx.gbl...
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.)

Nov 18 '05 #7
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.)


Nov 18 '05 #8

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

Similar topics

4
by: Tim Meagher | last post by:
I am trying to use both validation controls and to add submit button attributes, but when I add the button attributes, the javascript fpr the validation controls is no longer created for the page. ...
6
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
2
by: Martyn Fewtrell | last post by:
Dear All I have a Windows 2003 Server with IIS6 where the validation controls on ASP.Net pages no longer work. I believe it to be specific to the server as if I create an ASP.Net page on the...
2
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
9
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see)...
9
by: Bill Long | last post by:
I have a control that simply displays a list of links. Following one of the links doesn't post back or redirect to another page, it simply hides the current panel and shows the one you selected......
2
by: Tim Frawley | last post by:
Source code attached indicates my problem with validation and a button bar save button. Fill the Textbox with some text then tab off the control. The message box will display the text in the...
1
by: Buddy Ackerman | last post by:
I don't know what the problem is. I have a form with several controls that need to be validated, I put a validation group in every form control, every validatoino control, the submit button and...
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
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.