RequiredFieldValidator wont allow user to leave page - asp.net

I have Required field validators on some of my textboxes on some pages but when the user clicks on that page and then tries to click on a different page it wont let the user leave the page until the textboxes have been filled
How do i overcome this?

tries to click on a different page it wont let the user leave the page
I assume clicking on a different page requires the page to post back to server again.
If so, set the control's CausesValidation="False".
For example,
<asp:Button ID="Button1" runat="server" CausesValidation="False"/>

Related

How to redirect to another page with using a function on that page with asp link

I am new to asp.net. So just learning everything step by step.
I have created a web project with the template.
On Page one, I have a button and a textbox with no action defined yet.
On Page two I have a button and a textbox and I also have db connections works from the button.
What I want to do is, if user writes something and click button on first page, I want to go page 2 and acts as clicked button.
I want to run some action on page two with parameter from page on.
I think this is possible with redireciton mechanism
I will post the code here. can anyone help me . I may be wrong as I am new to this language.
I can do it with a button but I want to do it with a asp link
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="BringPage2" />
Right now this is a link but I want to make it a button
<p>Bring Page 2 ยป<input id="txtBoxAlan" name="txtBoxAlan" type="text" />
Instead of redirect, I just used href as href="Default1.aspx"

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 Login control focus in FireFox

I am using the Login control. Just in FireFox, I am finding that I cannot click directly on the UserName field. I need to tab through all the other elements on that page. Just wondering if there is a work around to this issue?
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false" OnLoggedIn="LoginUser_LoggedIn">
You can do this by adding the following code to the Page_Load method on your login page:
AppLogin.Focus();
this.Form.DefaultButton = "ctl00$BodyPlaceHolder$AppLogin$LoginButton";
This will also cause the "login" button to be clicked when you click enter.
Note: The full "path" (ctl100$BodyPlaceHolder...) may vary slightly depending on whether or not you're using master pages, panels, etc. You can simply view the element on the page in your favorite inspector and find the rendered name for the login button.
More details can be found at my blog here.

Requiredfieldvalidtor in asp.net stops me from going back?

When a user clicks a link, he's sent to a register form. In this form I have certain fields that need to be filled in. So I use required field validator on them.
On the page there is also a Back button, incase the user doesn't want to register. But when you press back, it says you need to fill in the fields or you won't go back.
Any suggestions on how this can be resolved?
Set the CausesValidation property on the back button to false:
<asp:Button id="btnBack" runat="server" CausesValidation="false" OnClick="btnBack_Click" Text="Back" />

Asp.net regularexpressionvalidator fires even when CausesValidation="false"

I have a regularexpression validator which validates a valid email. I have two buttons on my form. Submit and undo.
On undo, we are reverting the page state to default
submit has it validationgroup set while undo doesnot have any validationgroup and CausesValidation="false".
Now when i navigate to page and enter invalid emailaddress,i directly click undo. the validator fires and stops my page from posting.however if i press tab and navigate to other control and then click undo,the validator shows error message but posts back and furthur proessing is done.
This is very strange and i want the page to postback without any error message when i click undo.how to achieve it.
<tec:ThemedImageButton runat="server" ID="imgbtnSave" OnClick="imgbtnSave_Click"
ValidationGroup="CustomerGroup"/>
<tec:ThemedImageButton runat="server" ID="imgbtnCancel" CausesValidation="false"
OnClick="imgbtnCancel_Click" />
These are normal image buttons with added themes.CustomerGroup is the validation group for my textbox and regularexpressionvalidator
Are you possibly clicking the undo whilst your focus is still within the email textbox? If so, perhaps the issue is that the initial blur event of the textbox is firing which in turn is calling the email validator and preventing the click / submission.
The first thing to try is to make sure you can enter an invalid email address, move the focus onto a completely different area of the page and then press undo to determine if this is the cause.
Double check your settings.
You might want to check the code behind to make sure you are not overwriting the control settings there. For example, in code, you might have the CausesValidation set to "True" or something like that.
Until you post more information you could do the following in your Undo button:
<asp:Button ID="btnUndo" runat="server" Text="Undo"
OnClientClick="Page_ValidationActive = false;"
OnClick="btnUndo_Click" />
I don't recommend this as it might solve your problem but really doesn't explain what is wired up incorrectly but the Page_ValidationActive = false; will disable all client validation on your page.

Resources