Different buttons in the same form - asp.net

I have an asp form.it contains 3 menu item and save button under each menu[under each menu there are different fields]. I am doing validation using Ajax validators. My problem is after filling all mandatory fields for the first menu and on clicking the button the page is not post backing.Because i have some other fields mandatory for another menu.How can i solve this?

Try using Validation Groups
Validation groups allow you to organize validation controls on a page
as a set. Each validation group can perform validation independently
from other validation groups on the page. You create a validation
group by setting the ValidationGroup property to the same name (a
string) for all the controls you want to group. You can assign any
name to a validation group, but you must use the same name for all
members of the group.
Basically you need to assign a validation group name for each set of controls you wish to validate and then assign the same validation group name to the submit button associated with that group.
From the above link:
<asp:requiredfieldvalidator id="RequiredFieldValidator2"
controltovalidate="AgeTextBox"
validationgroup="PersonalInfoGroup"
errormessage="Enter your age."
runat="Server">
</asp:requiredfieldvalidator>
<br /><br />
<!--When Button1 is clicked, only validation
controls that are a part of PersonalInfoGroup
are validated.-->
<asp:button id="Button1"
text="Validate"
causesvalidation="true"
validationgroup="PersonalInfoGroup"
runat="Server" />

You need to use ValidationGroup property of Validation controls of ASP.Net.
Please provide the group name to each group of controls.
Please refer this link

Validation of fields will only be done when you mention the validation Group for the fields and in click event of the button. As you have other 2 menu's with mandatory fields with out any validation group name the button click event is trying to validate all the fields and not posting back. Give Validation Group names as A, B & C then try to validate...All the best

Related

Issue with Required Field validation in a asp.net application having two pages workflow

I have a asp.net application with two pages. The first page is having a next button and second page is having a back and submit button. The second page contains text box control with required field validtor.
As per current design, required field validator on 2nd page should get fired on clicking on submit button.
The issue I am having is :- User Fills the first page and then go to second page. Now, user wants to comeback to first page and then go to second page, the required field validator on text box is getting fired and showing up the error message. I dont want this. This should be like - text box should be blank and no error message should be displayed. Error messages should be displayed on clicking on the Submit button on the second page.
I tried couple of options :- 1. putting InitialValue on required field etc.. but no luck.
Could you pls help me out??
The following Markup should solve your problem :
<asp:TextBox ID="tbData" runat="server" ValidationGroup="Submit"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Button" ValidationGroup="Submit" />
<asp:Button ID="btnBack" runat="server" Text="Button" />
<asp:RequiredFieldValidator ID="reqFieldVal1" runat="server" ErrorMessage="Field must be filled in."
ControlToValidate="tbData" ValidationGroup="Submit"></asp:RequiredFieldValidator>
These fields use the ValidationGroup property to set which fields will cause the validation of which validator controls.
You will notice that there is no ValidationGroup property on the btnBack button as this should not cause validation.
For more information on this see the MSDN Article for Specifying Validation Groups

Asp.Net multiple submit buttons, enter submits only the first

I have a few submit buttons in my ASP.NET page. Everything works fine, but when a user hits enter button always the first submit button works. I want to fire each submit button with corresponding fields but cannot have multiple forms. Is it possible to group them without using forms?
You don't need forms, just wrap the related controls in their own panels and use the Panel.DefaultButton property.
Use the DefaultButton property to indicate which button gets clicked
when the Panel control has focus and the user presses the ENTER key.
The DefaultButton can be set to the identifier for a Button control or
any control that implements the IButtonControl interface except a
LinkButton control.
Please use DefaultButton property like this
<asp:Panel runat="server" DefaultButton="bt1">
<asp:TextBox runat="server" />
<asp:Button id="bt1" Text="Default" runat="server" />
</asp:Panel>
Please refer here :- ASP.NET DefaultButton Property

2 user controls on registered on one aspx page not validating validation properly

I have 2 user controls on registered on one aspx page.
UserControl1 us having one text box with require field and one submit button.
UserControl2 is also having one text box with requirefiled and save button.
Expected o/p is-
When I am clicking on any button out of 2(submit or save). Then only related text boxof that user control should be validate.
But the error is
Both text boxes are validate.
Please help me .
Set the ValidationGroup properties to limit which fields get validated when the buttons are pressed.
So for example, if these were contained within the first user control:
<asp:requiredfieldvalidator id="NameValidator"
controltovalidate="NameTextBox"
validationgroup="UserControlOne"
errormessage="required"
runat="Server" />
<asp:button id="Submit"
text="Submit"
causesvalidation="true"
validationgroup="UserControlOne"
runat="Server" />
Clicking the "Submit" button would only cause the validators that have UserControlOne specified as the ValidationGroup to validate.
Edit: When you call Page.Validate() you are validating every group on the page. Call the overloaded Page.Validate(validationGroup) to validate a specific one. e.g. Page.Validate("UserControlOne")

I want to apply a regularexpressionvalidator to selective fields in DetailsView ASP.NET 2.0 VB

Hello, I have been having trouble with this for a while now. I have a bound textbox within a Detailsview, to which I have added a RegularExpressionValidator (REV). The Regular Expression used is [a-zA-Z]*
After running the Web Form, the Edit button opens the fields. Any entries made cause the REV error msg to be displayed when the Update button is pressed, irrespective of the validation. The Update button continues to be displayed until the Cancel button is selected and the original record is returned to the screen replacing any entries.
The RequiredFieldValidator works correctly.
Ray Brown
I would suggest you FilteredTextBoxExtender of Ajax Control Toolkit instead of using REV.
It gives you the option to validate the input for many types of validation for numeric, letter, or even custom types for example:
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<ajaxToolkit:FilteredTextBoxExtender ID="ftbe" runat="server"
TargetControlID="TextBox3"
FilterType="LowercaseLetters, UppercaseLetters" />

requiredfield validator is preventing another form from submitting

I have a page with many forms in panels and usercontrols, and a requiredfield validator I just added to one form is preventing all of my other forms from submitting. what's the rule that I'm not following?
Are you using ValidationGroups? Try assigning each control with a validation group as well as the validator that you want to use. Something like:
<asp:TextBox ID="txt1" ValidationGroup="Group1" ruant="server" />
<asp:RequiredFieldValidator ID="rfv1" ... ValidationGroup="Group1" />
Note, if a button doesn't specify a validation group it will validate all controls that aren't assigned to a validation group.
You should be setting ValidationGroup property to a different value for each group of elements. Your validator's ValidationGroup must only be same with the control that submit its form.

Resources