I have a form in asp.net page. Whenever enter key is pressed the page is posted back.
I don't have any submit button in my form and using javascript to submit form.
<div class="row-fluid" align="center">
<a id="saveConfirm" class="textDecorationNone">
<div class="btn btn-primary">
<i class="icon-ok icon-white"></i> Add
</div>
</a>
<asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CssClass="btn" CausesValidation="false" OnClick="btnCancel_Click">
<i class="icon-remove"></i> Cancel
</asp:LinkButton>
</div>
row('#saveConfirm').click(function (){
//submit form
});
This can be addressed I believe with the accepted solution of the following post:
ASP.Net page enter key causing post back
Quoting:
You could set the DefaultButton on the Form or a Panel. This way you have full control what happens.
Set UseSubmitBehavior="False" on your Buttons. This disables the "AutoPostback" on Enter.
A possible javascript solution for ASP.NET is covered under this solution:
Disable default button in ASP.NET [duplicate]
use Updated Panel which avoid postback while enter.
Related
I have a textbox and save button on a pop-up, the textbox has a required field validator. I have a scenario, if the user accidentally forgets to enter data in the textbox and click save the required field validator kicks in, which is expected. But, now if the user enters data in the textbox and clicks on 'save', the record doesn't get saved on the first click instead it needs an additional click. I know the reason for this: it is not doing a postback when the button is clicked for first time, but for the second time it does and saves the data.
Does anyone know the workaround for this? The end user is getting annoyed by that additional click. Please note there is no javascript function associated with it. It is autogenerated javascript from the browser.
Code:
<div class="row">
<div class="col-md-12">
<div class="form-group">
<asp:Label runat="server" Text="" AssociatedControlID="txtTitle">
Title<span class="text-danger">*</span>
</asp:Label>
<asp:TextBox runat="server" CssClass="form-control" ID="txtTitle" >
</asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtTitle" Display="Dynamic" ErrorMessage="Required" ValidationGroup="questionTitle" CssClass="text-danger">
</asp:RequiredFieldValidator>
</div>
</div>
</div>
Save button:
<div class="row">
<div class="col-md-3 col-md-offset-9">
<asp:LinkButton runat="server" ID="lnkSave" CssClass="btn btn-lg btn-block btn-success btn-lg" role="button" ValidationGroup="questionTitle" OnClick="lnkSave_Click">
<i class="fa fa-floppy-o"></i> Save
</asp:LinkButton>
</div>
</div>
It seems like a common issue with the validator.
The validator error is suppose to clear out when lose focus to the textbox
however, apparently if your validator Display is set to Dynamic, when the error message appear, it will cause the triggering clearing the validator error to fail.
hence the clicking twice (first click trigger clear error which should have been trigger earlier but failed, second trigger actual form post)
solution is to change your RequiredFieldValidator Display to Static
more info checkout
RequiredFieldValidator have to click twice
RequiredFieldValidator requires user to click twice
I have a very basic submit button without a postbackurl specified but it creates a webresources.axd reference. I did see Why is my ASP.NET page injecting this WebResource.axd Javascript file? but I don't have postbackurl in the statement.
<form method="post" action="/thispage" id="formAlpha">
<asp:button ID="cmdSubmit" text="Submit" runat="server" />
</form>
Remove the button, there's no axd. Is there something else that could be causing it? I don't use JQuery.
I have HTML code of a sign in button:
<a href="Login.aspx" id="signin" runat="server" class="navbar-btn btn-success btn right">
Sign In
</a>
and a C# if statement that checks whether you are connected. If yes, I want to change the button text to Sign Out.
I tried to use the id of the HTML button signin in C# with signin.Attributes but I don't know how.
signin.InnerText = "Sign Out!";
I have an C# ASP.net website that is using FullCalendar (http://arshaw.com/fullcalendar/).
I want to grab all the calendar events and save them to my SQL database. I have added the following button which calls a javascript function:
<script type="text/javascript">
function save() {
alert('save');
//this will save to database...
}
</script>
<asp:Button ID="btnSave" runat="server" OnClientClick=" return save();" Text="Save" />
I notice that when I click the button the message appears but then the whole calendar just disappears from my page, why is this? and how can I prevent it.
It sounds like you're wanting to keep the page from submitting with this button. Adding return false; to your save() function will prevent the postback from occurring. If that is not right and you have a server-side click event for this button, in it, you will need to emit the javascript needed to recreate the calendar.
Use a HTML input button
<input type="button" id="btnSave" runat="server" Value="save" onclick="save()" />
I feel with this particular problem I have to explain how my webpage works, otherwise it might not make sense to anyone. The page will load, you will be given some text and the option to click on a asp.net combobox filled with options, when you select one of them, the page will reload and get all the information in relation to that user and display it in a dynamically created HTML table.
After this there are two divs that runat server and dependent on if the user has uploaded a file will display an option of changing the file, or adding a new one.
I have a standard html button that when is clicked is meant to run my JavaScript function, but when you click on the button it fires my aspxcombobox code again. I will attach all my code that I feel might be useful.
HTML for DIVS
<div id ="upload" runat = "server" visible = "false" class="default">
<asp:Label ID="uploadlbl" runat="server" Text="Upload driving licence" style="color:Red"></asp:Label>
<dx:ASPxUploadControl ID="LicenceUpload" runat="server">
</dx:ASPxUploadControl>
<dx:ASPxButton ID="UploadButton" runat="server" Text="Upload" style="margin-left: 2px">
</dx:ASPxButton>
</div>
<div id="ChangeUpload" runat="server" visible="false" class="default">
<span>Licence already uploaded</span>
<br />
<button id="changeLicence" onclick="changeLicence()">Change Licence?</button>
</div>
JAVASCRIPT
function changeLicence() {
alert('test');
}
It's a submit button. It submits the form it is in. Since you are using ASP.NET, the entire page is probably in a form.
Add type="button" to make it a non-submit button.
default behavior of button is submit, Add type="button" attribute so that it doesn't submits form.
<button
type="button"
id="changeLicence"
onclick="changeLicence()">Change Licence?</button>