G
Guest
I am facing some issues with the webforms DefaultButton functionality:
#1 One text box ==> hitting enter works in IE but not in Firefox (1.5)
#2 One text box and req. field validator ==> problem in IE
#3 two text boxes ==> not even a postbak in Firefox.
The three problems I have could be simply reproduced creating a new webform
and pasting the code below in the codebehind file.
TextBox bx1;
TextBox bx2;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
Validate();
bx1 = new TextBox();
bx1.ID = "bx1";
//bx2 = new TextBox(); // uncomment this line for problem #3
//bx2.ID = "bx2"; // uncomment this line for problem #3
RequiredFieldValidator rf = new RequiredFieldValidator();
rf.ControlToValidate = bx1.ID;
rf.EnableClientScript = true;
rf.ErrorMessage = "mandatory";
LinkButton lbSubmit = new LinkButton();
lbSubmit.ID = "lbSubmit";
lbSubmit.Click += new EventHandler(lbSubmit_Click);
lbSubmit.Text = "submit";
form1.DefaultFocus = bx1.ID;
form1.DefaultButton = lbSubmit.ID;
form1.Controls.Add(bx1);
//form1.Controls.Add(bx1); // uncomment this line for problem #3
//form1.Controls.Add(rf); // uncomment this line for problem #2
form1.Controls.Add(lbSubmit);
}
void lbSubmit_Click(object sender, EventArgs e)
{
form1.Controls.Add(new LiteralControl("lbSubmit_Click: Text is: " +
bx1.Text));
}
Finally, more detailed description of the problems:
Problem #1:
Adding text in the textbox and hitting enter works in IE like expected: my
Click handler of the submit button is called.
However, this does not work in Firefox. Postback is triggered, but the click
handler is not called. My workaround for this is inserting the follwoign code
in Page_Load:
if (IsPostBack && Request.Form["__EVENTTARGET"] == "")
Search(this, EventArgs.Empty);
Problem #2:
If I add a required field validator for the text box (uncomment
form1.Controls.Add(rf); in code above), I am getting problems in IE, too:
When entering no text in the textbox and just hitting enter, the field
validator tells me I need to add text. After adding text and hitting enter,
thepostback is done but the click handler is not called.
If I then once again hit enter, another postback in done and now the click
handler is called.
Problem #3:
If I add an additional textbox to the form, Firefox will even stop doing the
postback!
Any help would be greatly appreciated.
Dieter
#1 One text box ==> hitting enter works in IE but not in Firefox (1.5)
#2 One text box and req. field validator ==> problem in IE
#3 two text boxes ==> not even a postbak in Firefox.
The three problems I have could be simply reproduced creating a new webform
and pasting the code below in the codebehind file.
TextBox bx1;
TextBox bx2;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
Validate();
bx1 = new TextBox();
bx1.ID = "bx1";
//bx2 = new TextBox(); // uncomment this line for problem #3
//bx2.ID = "bx2"; // uncomment this line for problem #3
RequiredFieldValidator rf = new RequiredFieldValidator();
rf.ControlToValidate = bx1.ID;
rf.EnableClientScript = true;
rf.ErrorMessage = "mandatory";
LinkButton lbSubmit = new LinkButton();
lbSubmit.ID = "lbSubmit";
lbSubmit.Click += new EventHandler(lbSubmit_Click);
lbSubmit.Text = "submit";
form1.DefaultFocus = bx1.ID;
form1.DefaultButton = lbSubmit.ID;
form1.Controls.Add(bx1);
//form1.Controls.Add(bx1); // uncomment this line for problem #3
//form1.Controls.Add(rf); // uncomment this line for problem #2
form1.Controls.Add(lbSubmit);
}
void lbSubmit_Click(object sender, EventArgs e)
{
form1.Controls.Add(new LiteralControl("lbSubmit_Click: Text is: " +
bx1.Text));
}
Finally, more detailed description of the problems:
Problem #1:
Adding text in the textbox and hitting enter works in IE like expected: my
Click handler of the submit button is called.
However, this does not work in Firefox. Postback is triggered, but the click
handler is not called. My workaround for this is inserting the follwoign code
in Page_Load:
if (IsPostBack && Request.Form["__EVENTTARGET"] == "")
Search(this, EventArgs.Empty);
Problem #2:
If I add a required field validator for the text box (uncomment
form1.Controls.Add(rf); in code above), I am getting problems in IE, too:
When entering no text in the textbox and just hitting enter, the field
validator tells me I need to add text. After adding text and hitting enter,
thepostback is done but the click handler is not called.
If I then once again hit enter, another postback in done and now the click
handler is called.
Problem #3:
If I add an additional textbox to the form, Firefox will even stop doing the
postback!
Any help would be greatly appreciated.
Dieter