473,748 Members | 5,429 Online
Bytes | Software Development & Data Engineering Community
+ 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 2873
Hi Ali,

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

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

Is that what you meant?

Ken

"A.M" <IH*******@sapm 123.com> wrote in message
news:OJ******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP11.phx.gbl...
Hi Ali,

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

http://msdn.microsoft.com/library/de...ationTopic.asp
Is that what you meant?

Ken

"A.M" <IH*******@sapm 123.com> wrote in message
news:OJ******** ******@TK2MSFTN GP12.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*******@sapm 123.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP11.phx.gbl...
Hi Ali,

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

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

Is that what you meant?

Ken

"A.M" <IH*******@sapm 123.com> wrote in message
news:OJ******** ******@TK2MSFTN GP12.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 customdatasolut ions dot us
"A.M" <IH*******@sapm 123.com> wrote in message
news:OJ******** ******@TK2MSFTN GP12.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
ValidatorValida te(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.

ValidatorHookup Control(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.EventArg s e)
{

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

To make it clearly, I've also made a simple page to show how to implement
this, the page have two textboxes, two requiredfieldva lidator 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>Validati on</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="javas cript">
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:RequiredFi eldValidator id="rfvLeft" runat="server"
ErrorMessage="R equiredFieldVal idator Left"
ControlToValida te="txtLeft1"> </asp:RequiredFie ldValidator>
</td>
<td>
<asp:RequiredFi eldValidator id="rfvRight" runat="server"
ErrorMessage="R equiredFieldVal idator Right"
ControlToValida te="txtRight1"> </asp:RequiredFie ldValidator>
</td>
</tr>
</table>
</form>
</body>
</HTML>
----------------------------------------------------------------------------
-------------

-----------------------code behind page
class-----------------------------------------
public class Validation : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Text Box txtLeft1;
protected System.Web.UI.W ebControls.Text Box txtRight1;
protected System.Web.UI.W ebControls.Butt on btnVLeft;
protected System.Web.UI.W ebControls.Requ iredFieldValida tor rfvLeft;
protected System.Web.UI.W ebControls.Requ iredFieldValida tor rfvRight;
protected System.Web.UI.W ebControls.Butt on btnVRight;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
btnVLeft.Attrib utes.Add("onmou sedown","LeftVa lidator()");
btnVRight.Attri butes.Add("onmo usedown","Right Validator()");

}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnVLeft.C lick += new System.EventHan dler(this.btnVL eft_Click);
this.btnVRight. Click += new System.EventHan dler(this.btnVR ight_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

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

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

private void btnVRight_Click (object sender, System.EventArg s e)
{
Response.Write( "<br>Right Field is OK!");
rfvLeft.Enabled = false;
rfvRight.Enable d = 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.m icrosoft.com> wrote in message
news:ol******** ******@cpmsftng xa08.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
ValidatorValida te(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.

ValidatorHookup Control(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.EventArg s e)
{

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

To make it clearly, I've also made a simple page to show how to implement
this, the page have two textboxes, two requiredfieldva lidator 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>Validati on</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="javas cript">
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:RequiredFi eldValidator id="rfvLeft" runat="server"
ErrorMessage="R equiredFieldVal idator Left"
ControlToValida te="txtLeft1"> </asp:RequiredFie ldValidator>
</td>
<td>
<asp:RequiredFi eldValidator id="rfvRight" runat="server"
ErrorMessage="R equiredFieldVal idator Right"
ControlToValida te="txtRight1"> </asp:RequiredFie ldValidator>
</td>
</tr>
</table>
</form>
</body>
</HTML>
-------------------------------------------------------------------------- -- -------------

-----------------------code behind page
class-----------------------------------------
public class Validation : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Text Box txtLeft1;
protected System.Web.UI.W ebControls.Text Box txtRight1;
protected System.Web.UI.W ebControls.Butt on btnVLeft;
protected System.Web.UI.W ebControls.Requ iredFieldValida tor rfvLeft;
protected System.Web.UI.W ebControls.Requ iredFieldValida tor rfvRight;
protected System.Web.UI.W ebControls.Butt on btnVRight;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
btnVLeft.Attrib utes.Add("onmou sedown","LeftVa lidator()");
btnVRight.Attri butes.Add("onmo usedown","Right Validator()");

}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnVLeft.C lick += new System.EventHan dler(this.btnVL eft_Click);
this.btnVRight. Click += new System.EventHan dler(this.btnVR ight_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

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

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

private void btnVRight_Click (object sender, System.EventArg s e)
{
Response.Write( "<br>Right Field is OK!");
rfvLeft.Enabled = false;
rfvRight.Enable d = 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=serv er"
<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
2625
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. How can I use both? Thank you, Tim Meagher
6
3708
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 confirmation message. By adding just an confirm attribute for 'onclick' event of the button doesn't work with validation controls. Is there any short way to go around this. Thanks Nedu
14
6310
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) show the error message next to the control. For example, if the text field is empty with RequiredField Validator control, it can show the value in ControlToValidate property in two ways as I mentioned. Please advise. Thanks!
2
4001
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 IIS Server of my Workstation (Win XP) with a text box, button and required field validator, this works fine. If I create the same page on the IIS6 Windows 2003 Server the validation control doesn't stop the post. I've tried different browsers and...
2
3733
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 all the messages to a message box (ShowMessageBox=true). The required field validation error messages show up in the summary just fine but I can't get the custom validation message to show up if invalid. So far I have the summary control...
9
2224
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) in page_load, or elsewhere, that says page.validate, no control says "causesvalidation=true", and the AutoEventWireup is set to false. So I would think that the control's server event function would NOT execute, but it does execute right after...
9
3187
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... So the behavour is similar to a tab control. The user is expected to fill out required data on each of the panels before pressing a submit button which is visible from all panels. Problem I have is validating the data entered by the user. I...
2
6710
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 textbox from the Validating event. Now put the focus back on the textbox click the button bar button. Nothing happens. The form causes validation is true, so is the button bar and the control.
1
1816
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 the validation summary control. I want it to do client side validation so I set every validation control display property to none and set the validation summary control to ShowMessage to true and ShowSummary to false. Als form controls set...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4597
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3303
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 we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.