DefaultButton What's wrong with this code?

  • Thread starter Thread starter mablejune
  • Start date Start date
M

mablejune

HtmlForm frm = (HtmlForm)Master.FindControl("formMain");
frm.DefaultButton = "btnSubmit";
txtCall.Focus();

Running this code produces the following error message:

The DefaultButton of 'formMain' must be the ID of a control of type
IButtonControl.

btnSubmit is a System.Web.UI.WebControls.Button which implements
IButtonControl.

Is this a bug?
 
On Tue, 13 Dec 2005 21:00:49 -0800, "Steve C. Orr [MVP, MCSD]"

Thank you Steve, but neither of the links you sent answers my question
about why the code doesn't work. The code is from ASP.NET 2.0 and the
Default button property is a new property of the form object. My
question is why does this not work as it should.
 
Try assigning DefaultButton to the ClientID of the button.

Something like this:
HtmlForm frm = (HtmlForm)Master.FindControl("formMain");
IButtonControlbtn = (IButtonControl)Master.FindControl("btnSubmit");
frm.DefaultButton = btn.ClientID;
txtCall.Focus();

Joshua Flanagan
http://flimflan.com/blog
 
On Wed, 14 Dec 2005 18:04:53 -0600, Joshua Flanagan <[email protected]>
wrote:

It's a bug. Here's the workaround...

HtmlForm frm = (HtmlForm)Master.FindControl("formMain");
Button btn = (Button)this.btnSubmit;
frm.DefaultButton = btn.UniqueID;
 
Sorry, UniqueID is what I meant (didn't have the docs in front of me).
That is the correct behavior - it is not a bug.
 
On Thu, 15 Dec 2005 11:19:30 -0600, Joshua Flanagan <[email protected]>
wrote:

When it was reported a year ago it was a bug. They simply rewrote the
help files to cover it. Check the bug history on it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top