Showing posts with label enter. Show all posts
Showing posts with label enter. Show all posts

Monday, March 26, 2012

pressing enter on a form in an updatepanel

Hi,

Im trying to fix my forms so that enter does not submit forms on IE/Mozilla/Safari but cannot find a solution. First off I used :

/*--- Disable enter key ----*/function kH(e) { var pK = e ? e.which : window.event.keyCode;return pK != 13;} document.onkeypress = kH;if (document.layers) document.captureEvents(Event.KEYPRESS);/*------------*/

on all pages but it didnt seem to work. So then I decided to try catch the keypress from forms like input and textarea and I used the following (onkeypress="return ifEnter(this,event);")

function ifEnter(field,event) { var theCode =event.keyCode ?event.keyCode :event.which ?event.which :event.charCode;if (theCode == 13) {return false; }else {return true; }}

but again it doesnt seem to work. Another thing I noticed is that it seems to submit the form as asp.net would. My default form submission is a next button which moves to another page when submitted, but when someone hits enter, the same page reloads with a standard postback i think.

What I want to know is why the javascript wont work? Is it because the form is in an updatepanel? How can I manage the user pressing enter in an update panel?

Why doesnt the user pressing enter activate the DefaultButton action of the panel which its in?

All help much appreciated!

C

Edit: never mind, I see the behavior now.

I saw the behavior with only one textbox. Adding a second set to invisible, perhttp://aspnet.4guysfromrolla.com/articles/060805-1.aspx, fixed it.

See if that helps for you.


My form allready had multiple textboxes etc.

The problem seesm to be only in firefox. Ive found a partial fix for my problem which at least submits my default button and saves the form instead of performing a callback here :

http://www.andornot.com/about/developerblog/2007/09/fix-firefox-defaultbutton-issue-with.aspx

Im still looking for a simple way to prevent enter key form posting back in certain textareas or input text boxes in firefox pretty please.

Previous rows display when a new row add in GridView (in UpdatePanel) after hitting enter

I am having a problem in GridView using UpdatePanel. I have UpdatePanel which contains a GridView. When I enter rows in GridView and refresh a page it remove rows from Grid and if I enter again it shows only new entered row, works fine.

But when I enter few rows in Grid then click on address bar hit enter on it, it removes the rows from Grid and when I again enter a row again then it shows new with previous rows.

Can anybody tell me where am I doing a mistake.

Thanks in advance.

It works fine in debug mode but when I deploy the application on server, it shows previous records with new record.

Any idea?

Thanks in advance.

Probably, I found a bug [NewLine in MultiLine TextBox]

Try to run this sample (enter to textbox some lines of text, and then click "Post"):

<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits=".WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="updPanel" ChildrenAsTriggers="true" runat="server"><ContentTemplate><asp:TextBox ID="txtTest" runat="server" TextMode="MultiLine" /><asp:Button ID="butTest" runat="server" Text="Post" /><br /><div style="border:solid 1px red; padding:20px;"><%=txtTest.Text.Replace(Environment.NewLine, "<br/>")%></div></ContentTemplate></asp:UpdatePanel> </div> </form></body></html>

I am using a release version of AST.NET AJAX.

What's the bug?

If you enter some lines of text in Firefox into textbox, and then post it to the server via AJAX, newline symbols will be damaged.

In Opera and IE all works fine.


"Firefox" would be the reason I didn't see the error initially. That is a pretty annoying bug.

I'm experiencing this exact same issue ... did you get it resolved?

Cheers!