G
Geoff
I have translated the DefaultButton() function, available at
http://www.kamp-hansen.dk/pages/showdoc.asp?id=28&menuid=21&menuid=18
into C# but I am experiencing a problematic side-effect. If you
double click a text box, and IE pops up a list of the values you have
recently used, and you arrow key down, or move the mouse down, to
highlight one, and THEN hit the enter key, the Enter get processed,
and the button gets clicked, BEFORE the text makes it into the
TextBox. Can anyone provide a solution to this problem?
using System.Text;
public void DefaultButton(System.Web.UI.Page Page, TextBox
objTextControl, Button objDefaultbutton)
{
StringBuilder sScript = new StringBuilder();
sScript.Append("<SCRIPT language=\"javascript\">" +
Environment.NewLine);
sScript.Append("function fnTrapKD(btn){" + Environment.NewLine);
sScript.Append(" if (document.all){" + Environment.NewLine);
sScript.Append(" if (event.keyCode == 13)" + Environment.NewLine);
sScript.Append(" { " + Environment.NewLine);
sScript.Append(" event.returnValue=false;" +
Environment.NewLine);
sScript.Append(" event.cancel = true;" + Environment.NewLine);
sScript.Append(" btn.click();" + Environment.NewLine);
sScript.Append(" } " + Environment.NewLine);
sScript.Append(" } " + Environment.NewLine);
sScript.Append("}" + Environment.NewLine);
sScript.Append("</SCRIPT>" + Environment.NewLine);
objTextControl.Attributes.Add("onkeydown", "fnTrapKD(document.all." +
objDefaultbutton.ClientID + ")");
Page.RegisterStartupScript("ForceDefaultToScript",
sScript.ToString());
}
http://www.kamp-hansen.dk/pages/showdoc.asp?id=28&menuid=21&menuid=18
into C# but I am experiencing a problematic side-effect. If you
double click a text box, and IE pops up a list of the values you have
recently used, and you arrow key down, or move the mouse down, to
highlight one, and THEN hit the enter key, the Enter get processed,
and the button gets clicked, BEFORE the text makes it into the
TextBox. Can anyone provide a solution to this problem?
using System.Text;
public void DefaultButton(System.Web.UI.Page Page, TextBox
objTextControl, Button objDefaultbutton)
{
StringBuilder sScript = new StringBuilder();
sScript.Append("<SCRIPT language=\"javascript\">" +
Environment.NewLine);
sScript.Append("function fnTrapKD(btn){" + Environment.NewLine);
sScript.Append(" if (document.all){" + Environment.NewLine);
sScript.Append(" if (event.keyCode == 13)" + Environment.NewLine);
sScript.Append(" { " + Environment.NewLine);
sScript.Append(" event.returnValue=false;" +
Environment.NewLine);
sScript.Append(" event.cancel = true;" + Environment.NewLine);
sScript.Append(" btn.click();" + Environment.NewLine);
sScript.Append(" } " + Environment.NewLine);
sScript.Append(" } " + Environment.NewLine);
sScript.Append("}" + Environment.NewLine);
sScript.Append("</SCRIPT>" + Environment.NewLine);
objTextControl.Attributes.Add("onkeydown", "fnTrapKD(document.all." +
objDefaultbutton.ClientID + ")");
Page.RegisterStartupScript("ForceDefaultToScript",
sScript.ToString());
}