![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| Hi, I have a situation which is causing me to pull the few last hairs on my head. I have this Asp.Net form in which I have defined a default button: btnFind and I have it defined as follows: Code: <form id=”form1″ runat=”server” defaultbutton=”btnFind″ > something really strange happens, it doesn't work on Firefox. I'm really stumbled to make this work. I'm using Visual Studio 2005 .Net Framework 2.0, and Ajax Can someone please help me? |
| Sponsored Links |
|
#2
| ||||
| ||||
| A solution I've found, provided you either have 1 button on the page, or the default button is the first that's rendered is to use Javascript. Within the head of your content page include:- Code: <script type="text/javascript">
function press(evt)
{
if(evt.which || evt.keyCode){
if ((evt.which == 13) || (evt.keyCode == 13)) {
//Use the id of the button you want as the default.
var buttonid = '<%=Button1.ClientID %>';
__doPostBack(buttonid,'');
returntrue;
}
} else {
returnfalse;
}
}
</script>
Code: sub Page_Load()
if not ispostback then
form1.attributes.add("onkeypress", "press(event);")
end if
end sub
Last edited by richyrich; April 1st, 2008 at 08:45 AM. Reason: Tidied up code |
|
#3
| |||
| |||
| Thanks for your reply richy I get the following error with the code you provided: System.Web.UI.HtmlControls.HtmlForm' does not contain a definition for 'attributes' |
|
#5
| |||
| |||
| Thanks for your help, I still can't figure it out ![]() Code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="Test" %>
<!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 id="Head1" runat="server">
<title>Employee Listing</title>
<script type="text/javascript">
function press(evt)
{
if(evt.which || evt.keyCode){
if ((evt.which == 13) || (evt.keyCode == 13)) {
//Use the id of the button you want as the default.
var buttonid = '<%=Button1.ClientID %>';
__doPostBack(buttonid,'');
returntrue;
}
} else { returnfalse; }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="MyScriptManager" runat="server" />
<asp:updatepanel ID="MyUpdatePanel" runat="server">
<ContentTemplate>
<asp:Label ID="msg" runat="server" />
<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnFind" runat="server" Text="Find" onclick="btnFind_Click" />
</contentTemplate>
</form>
</body>
</html>
Code: protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
form1.attributes.add("onkeypress", "press(event);")
}
protected void btnFind_Click(object sender, EventArgs e)
{
msg.Text = "The Name to Search for is " + txtName.Text;
}
Last edited by Devwhiz; April 2nd, 2008 at 10:39 AM. |
|
#6
| ||||
| ||||
| Don't know if this will have an effect, but you hadn't changed the id of the button to be default in the JS and there were a couple of spaces missing. You were also missing the end UpdatePanel tag. Also, add the onkeypress to the form tag itself and remove the form1.attributes.add line completely from your code behind. Code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="Test" %>
<!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 id="Head1" runat="server">
<title>Employee Listing</title>
<script type="text/javascript">
function press(evt)
{
if(evt.which || evt.keyCode){
if ((evt.which == 13) || (evt.keyCode == 13))
{
//Use the id of the button you want as the default.
var buttonid = '<%=btnFind.ClientID %>';
__doPostBack(buttonid,'');
return true;
}
} else {
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server" onkeypress="press(event);">
<asp:ScriptManager ID="MyScriptManager" runat="server" />
<asp:updatepanel ID="MyUpdatePanel" runat="server">
<ContentTemplate>
<asp:Label ID="msg" runat="server />
<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnFind" runat="server onclick="btnFind_Click" />
</contentTemplate>
</asp:updatepanel>
</form>
</body>
</html>
Last edited by richyrich; April 1st, 2008 at 06:16 PM. |
|
#7
| |||
| |||
| Thanks richy, this works ![]() But what if I had different tabpanels? Would this work? |
|
#9
| |||
| |||
| yes |
|
#10
| ||||
| ||||
| As this thread has been inactive for more than 30 day -- it has been closed. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|