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
Related
I have three textbox and one button. Here is my problem:
I use autopostback="true" in textbox, i entered some value and after first click of the button is not working. Then i click again, second click is working. I looked on F12 developer tool on Browser, there is no an error. When i set autopostback="false" than button click is working without any problem.
I would like to use autopostback="true" because it helps me. I think there is a focus problem because when i click out of textbox and than click on the button, button works with autopostback="true"
Do you have any idea for solution of this problem. All controls are working server-side.
<asp:Textbox ID="Name" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="Surname" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Textbox ID="City" runat="server" ValidationGroup="myval" AutoPostBack="true"></asp:Textbox>
<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" ValidationGroup="myval"></asp:Button>
I found a solution. It's not stable solution but however it's working. I hope it helps you too. My solution is:
<asp:Button ID="send_btn" runat="server Text="Check and Send" OnClick="send_btn_Click" OnClientClick="return true;" ValidationGroup="myval"></asp:Button>
I added OnClientClick="return true;" and button click is working on first click now.
If you have better solution waiting for your response.
I have just started a new ASP.NET web application and I am totally new to everything and after moving a few things round I have been getting this error and I don't understand what it means.
It happens when I go to enter anything in the Password box.
Could someone please help me out on this issue.
EDIT:
<li>
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" onkeypress="capLock(event)" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password" CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
Try to do that inside
window.onload = function(){
// code goes here
}
I think you are trying to access DOM even before it is being created.
the document.getElementById('divMayus') is undefined
document.getElementById("divMayus") is returning null or undefined.
You should look at the rendered html and find the div that you are trying to reference to make sure the id is the same as you are trying to reach. Asp.net alters the ids of server controls depending on their containers. So if you moved stuff around, the id may have also been changed.
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
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.
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?