I have an asp.net Web Application, i have login screen in Application.
In userName and password field i have used required field validator as follows :
<td style="width: 160px">
<asp:TextBox ID="txtUserNm" runat="server" CssClass="txtSingleline txtBack-Color txtRequireBorder-Color required" Height="18px" Width="150px" TabIndex="1" MaxLength="50" onblur="ValidatorOnChange(event);showhide();"></asp:TextBox>
</td>
<td style="width: 140px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
Width="150px" SetFocusOnError="true" ErrorMessage="Please enter Username" ControlToValidate="txtUserNm" ValidationGroup="a"></asp:RequiredFieldValidator>
when i focus on UserName textbox and Press Tab , i am unable to loos the focus from the TextBox because of RequiredField Validator. it happens only in Chrome and IE9 . but working well in firefox.
what can be solution to loose the focus from the Textbox when using Requiredfield validator ???
Thanks
Simple... just remove the SetFocusOnError="true" or set it to false.
The only downside is you can only validate the form on form post back, not on the fly.
But, it's not even such a pain in the neck, since even if you remove this property, validation works fine in both normal web forms, and ajax update panels.
I assume that you should manually assign tabindex property to your controls in order to define loop by pressing tab.
Related
I have a form with this markup:
<asp:TextBox ID="txtMeMail" runat="server" Width="250px" ToolTip="error"></asp:TextBox>
<asp:RegularExpressionValidator CssClass="mandatory msg" ID="RegularExpressionValidator1" runat="server" Display="Dynamic" ValidationGroup="validEmail" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="txtMeMail" ErrorMessage="error" EnableClientScript="true" />
<button class="button noMarginLeft" runat="server" validationgroup="validEmail" accesskey="S" id="btnSave" onserverclick="BtnSave_Click" value="Page.FIUserEdit.SaveButton.Label">
<asp:Label runat="server" Text="label"></asp:Label>
</button>
When I input "abc" and remove the focus from the text box, the invalid email message shows up. After that, I correct the text box with a valid email and I keep the focus on the text box, then I click the submit button. The validation message disappears but the form does not submit.
Is there any way to validate and then submit the form?
Try using
<asp:Button class="button noMarginLeft" runat="server" ValidationGroup="validEmail" accesskey="S" ID="btnSave" OnServerClick="BtnSave_Click" value="Page.FIUserEdit.SaveButton.Label" />
The problem is that you use the ordinary html Button tag. Although it can work it is not recommended because you lose functionality, see How can I use the button tag with ASP.NET?
If you do want content inside the button then use the LinkButton.
Hello guys I am making a login form where i want the txtpassword textbox to have
TextMode="password" but as soon as I add this attribute all my styles are gone I want to know how can i hide the password (instead show dot like characters) and also have styles applied here is my code if you guys need
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<%--this runs perfectly--%>
<br />
<asp:TextBox ID="txtpassword" TextMode="Password" runat="server"></asp:TextBox>
<%--styles aren't there as soon as i add TextMode or type attributes--%>
I have a searchbar on my site, but the problem is that when the user is in their profile I display a changepassword asp.net object. I'm using Visual Studio 2012.
<asp:ChangePassword ID="ChangePassword1" runat="server" SuccessTextStyle-HorizontalAlign="Center" CancelButtonText="" CancelButtonType="Link" ContinueButtonText="" ContinueButtonType="Link">
</asp:ChangePassword>
When I try to add my searchbar
<asp:TextBox ID="txtSearch123" runat="server" OnTextChanged="txtSearch123_TextChanged" Width="217px" Text="Search for an item..." OnClick="this.value=''" AutoCompleteType="Disabled"></asp:TextBox>
When the user presses enter, the search never completes because the textboxes inside in the change password are empty and they light up as if the user is trying to change their password. Even though they aren't linked what so ever.
Any ideas?
Following Works:
<asp:ChangePassword ID="ChangePassword2" runat="server" ValidationGroup="Password"> </asp:ChangePassword>
<asp:TextBox ID="txtSearch123" runat="server" OnTextChanged="txtSearch123_TextChanged" Width="155px" Text="Search for an item..." OnClick="this.value=''" AutoCompleteType="Disabled" ValidationGroup="SearchItem"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="" Width="0" Height="0" ValidationGroup="SearchItem" Visible="false" />
IF that does not work, do the following...
Make a button with the same validation as the text box.
Set the height and width to the button to 0.
Set the border type to none
Set the background of the button to the background you are trying to place it on.
Boom, your button is hidden in plain sight and your validation group still works.
<asp:TextBox ID="txtSearch123" runat="server" OnTextChanged="txtSearch123_TextChanged" Width="217px" Text="Search for an item..." OnClick="this.value=''" AutoCompleteType="Disabled" ValidationGroup="SearchItem"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="" Width="0" Height="0" ValidationGroup="SearchItem" BackColor="#5F605F" BorderStyle="None" />
There's two concepts you need to understand first.
The fact is, that everything on a (normal) ASP.NET page is inside one single form. This also means that things like "pressing enter to send form" are a bit tricky, since they submit the whole form, which usually isn't what you want.
Now to the concepts:
ValidationGroup - this setting on .NET validators (and buttons etc.) allows you to separate different logical forms inside the one superform. The validators will only evaluate if the originator of the submit action (eg. the "change password button") is in the same ValidationGroup. Properly configuring validation groups should make this part of your issue disappear.
What happens on enter key press - by default, you send the whole form, without doing any button's action. So, if you have multiple logical forms on one page, you have to put each inside its own Panel, which has a DefaultButton property, which says "if I press enter inside this panel, it will act as if I clicked on this button".
SET ValidationGroup in your TextBox
<asp:TextBox ID="txtSearch123" runat="server" OnTextChanged="txtSearch123_TextChanged" Width="217px" Text="Search for an item..." OnClick="this.value=''" AutoCompleteType="Disabled" ValidaionGroup="Something"></asp:TextBox>
Specifying Validation Groups
We've got a web application written with VS2005, running on an ASP.NET 2.0 platform, which has a problem.
This is the code:
<td>
<asp:ImageButton ID="ibInsertEmpty_4" runat="server" ImageUrl="~/Images/ok_green.png"
OnClick="gv_mwl_EmptyInsert" />
</td>
<td>
<asp:TextBox ID="emptyMWL_ID" runat="server" Width="6em"></asp:TextBox>
<asp:RequiredFieldValidator ID="valemptyMWL_ID" runat="server"
ControlToValidate="emptyMWL_ID" ErrorMessage="<br>Link ID must not be empty!"
SetFocusOnError="true" display="Dynamic" />
</td>
which is suppose to show an error if the user clicks the button when the textbox is empty.
Well, that happens, but even after the error is shown, it still calls the onclick handler gv_mwl_EmptyInsert, as if there was no error.
Why is this happening?
Unfortunately, I can't post a link to the website (because it's on an intranet, and it uses a database which requires authorisation), but I tried to make a small testcase which has the same problem, without success. So I don't know what to do now.
Add
ValidationGroup="SomeValidationGroup"
To both the Button, and the validator
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on the client side when I press the Cancel button, which has the CausesValidation attribute set to "False". How can I get this to stop?
I do not believe that Validation Groups are supported in 1.1.
Here's a code sample:
<asp:TextBox id="UsernameTextBox" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="UsernameTextBoxRequiredfieldvalidator" ControlToValidate="UsernameTextBox"
runat="server" ErrorMessage="This field is required."></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="UsernameTextBoxRegExValidator" runat="server" ControlToValidate="UsernameTextBox"
Display="Dynamic" ErrorMessage="Please specify a valid username (6 to 32 alphanumeric characters)."
ValidationExpression="[0-9,a-z,A-Z, ]{6,32}"></asp:RegularExpressionValidator>
<asp:Button CssClass="btn" id="addUserButton" runat="server" Text="Add User"></asp:Button>
<asp:Button CssClass="btn" id="cancelButton" runat="server" Text="Cancel" CausesValidation="False"></asp:Button>
Update: There was some dynamic page generating going on in the code behind that must have been messing it up, because when I cleaned that up it started working.
Validation Groups were not added to ASP.NET until version 2.0. This is a 1.1 question.
Double check your setting and make sure you are not overwriting it in the code behind.
Are they in separate validation groups (the button and validator controls)?
You're not manually calling the JS to do the client validation are you?