.NET har en egendomlig "feature": När jag trycker på Enter då markören befinner sig i en (Single Line-)TextBox sker PostBack men utan att Button_Click-handlern körs. Någon som har löst det problemet?
Här är någon annan som skriver om problemet:
There is a strange behavior quirk in the interaction between web browsers and the .NET framework which means that if you hit Enter in a Single-TextBox form it will post back to the server but the Button_Click handler is not executed.
This is apparently a legacy browser issue where, for a single textbox form, the button name is not sent as part of the response, leaving .NET with no idea what triggered the postback.
Possible workarounds are:
Always physically click the Submit button rather than pressing Enter.
Include a second TextBox that does nothing, just to avoid this "feature".
Download and use MetaBuilders' Default Buttons Control to safely link the Submit Button to the TextBox's enter key.
Hade ett sånt problem (eller nått liknande) löste det med ett javascript som när man tryckte return i textboxen skickade vidare en med rätt info te nästa sida.
function link(){
window.parent.Main.location = "bla.aspx?bla=" + escape(document.Top.SeekTB.value);
}
function keypressed(e){
var characterCode;
if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;characterCode = e.keyCode; //character code is contained in IE's keyCode property
}
if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
link();
return false;
}
else{
return true;
}
}
och i textboxen
onkeypress="return keypressed(event)"
På det viset kan man tex komma runt det. Samt även göra andra roliga saker. :bire
Skicka vidare till nästa sida?? Jag har ju en event kopplad till knappen, och det kräver ju PostBack. Inte vill man ju i ASP.NET skickas till nya sidor. I ASP måhända, men inte i ASP.NET. Eller missförstod jag dig?