how to bypass required field validation when clicking the cancel button? - html

I've used HTML input type for my textboxes to utilize the required attribute. now my dilemma is i cannot go out of the page without filling-up the fields with required attributes. Ive tried using causeValidation set to false but its not working. i can not change my textboxes to asp textboxes because it's going to be a large changes in the page. is there any other way to this?
<asp:Button runat="server" ID="buttonCancel" CssClass="cu-btn-direction" style="float:right; margin-right: 15px; margin-bottom: 60px;" Text="Cancel" CausesValidation="false" />
EDIT:
I tried adding validation group but didn't work... what works is setting the UseSubmitBehavior to false http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior%28v=vs.110%29.aspx but as explained in the link it will not work without js enabled. any other way?

use formnovalidate
<input type="submit" value="Cancel" formnovalidate>
this bypass all form validation like required

Related

How to bypass required fields when asp button and html text both present

In my case i have both ASP button and html text field which is required and two buttons.
Like this
<input type='text' runat='server' id='textfield' required/>
<asp:Button Text='submit' runat='server' onClick='clickEvent' id='submitButton'/>
<asp:button text='export' runat='server' onClick='exportEvent' id='exportButton'/>
Here when
i click submitButon and textfield empty then it triggers validation
and its good.
But when
i click exportButton that textfield triggers which is unwanted.
Notes:
1) i have tried EnableClientScript="False" and ValidateRequestMode='disabled' both of them didn't work
2) tried giving validation group in exportbutton didn't work and i couldn't apply that on pure html field
ASP Button has UseSubmitBehavior property, you can set that to false to bypass submit validations for the required button like below
<asp:button text='export' runat='server' onClick='exportEvent' id='exportButton' UseSubmitBehavior="false"/>

asp Textbox & HTML Input - Values always empty

I have an asp Textbox for a username and a HTML input for a password, these are both server controls and are contained in the master page (in a modal popup).
<input runat="server" Class="login-input" id="txtPassword" placeholder="Password" type="password"
<asp:Textbox style="float:left; margin-right:25px;" runat="server" id="txtUsername" Class="login-input" Placeholder="Username" name="txtUserName"/>
I also have a login button hooked up to a handler in the code behind. However the value of the 2 input boxes is always empty.
I had to include UseSubmitBehavior="False" on my button as this was the only way i could get my click event to
<asp:Button UseSubmitBehavior="False" runat="server" Class="login-button" ID="btnLogin" Text="Login" />
Not sure what's going on here, i have checked my code and definitely only have 1 form tag, which i heard can cause this.
It turned out that at runtime my modal was not contained within the tags.
Therefore i had to use
$('#divname').parent().appendTo($("form:first"));
within my script to move the elements back within the form tags.
(There were 2 modal elements outside) I found this out by using f12 dev tools/firebug.

Identifying main submit button for a form

I have a form which has a few text boxes, and two submit buttons. When a text box is selected, and I press Enter, the first submit button is triggered. However, this is not the button that should be pressed at that time. How can I make it so that when the Enter button is pressed, the second submit button (or at least, the last occurrence of the submit button) clicked?
I have an implementation of this currently using JavaScript, but I'm hoping there is a native option for it.
Its pretty tough to get more native than javascript. You're gonna need it here. By the way, the behavior you noticed is the expected behavior. The first submit button in your html is the one that will get sent with your header.
I guess if you really didn't want to use js, you could just put the other button first and then use css to position them correctly on the page itself.
If you are using asp .net then you can use "UseSubmitBehavior" property on the button. See below code.
<asp:TextBox runat="server" ID="txt1"></asp:TextBox> <br/>
<asp:Button runat="server" ID="btn1" UseSubmitBehavior="False" Text="1" OnClick="test1"/> <br/>
<asp:Button runat="server" ID="btn2" UseSubmitBehavior="True" Text="2" OnClick="test2"/>

Is their any asp net server control which could render <label> tag?

I want to render a <label> tag. But want to set some of it's properties while it's rendering like for and text value.
Actually my real problem is I want to associate a label with a radio button and this is the code so far I have:
<asp:RadioButton ID="Option4" GroupName="A" runat="server" />
<label for='<%=Option4.ClientID %>' id="lblOption4" runat="server">4</label>
But the problem with this code is that it is not working and rendering the for attibute's value as it is i.e. <%=Option4.ClientID %>. :-(
Is their any asp net server control which would render tag?
I don't want to set the Text property of the radio button due to some CSS limitations so plz do not give answers like why don't you set the Text property of the radio button.
if this is .NET 2.0 or later, then use the ASP.NET LABEL control.
<asp:RadioButton ID="Option4" GroupName="A" runat="server" />
<asp:Label AssociatedControlId="Option4" Text="4" runat="server" />
If this is to ultimately handle accessiblity issues you could try the following tutorial: Creating an Accessible LABEL control in ASP.NET

.NET HtmlButton always triggers validators

I have created a server control out of the HtmlButton with validation disabled.
<button runat="server" causesvalidation="false" />
NOT the input button!!!
<input type="button" runat="server />
I have a bunch of validators on my form and when i click the HtmlButton they still run the validators. If I use the input button there is no problem and the validators don't run.
Is this expected behavior or is this a bug?
I tried it and it works as expected. I think you should check your code, maybe you're enabling it at server-side.
<button runat="server" ID="btnSubmit" causesvalidation="false"
onserverclick="SubmitButton_Click"></button>
Just to overcome the problem, you can add validation group to your validations.
You have no id on your button? That might be causing an issue where it doesn't know what the button is called therefore not loading all attributes for it. Long shot but you never know.
Depends on where the validations are used and if they are in the same group.you add validation restrictions on validation groups.if they are not in a group maybe the form's post to server causes it to validate the controls.
All you have to do is set the attribute type="button". The default must be submit.