DefaultButton What's wrong with this code?

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?
 
M

mablejune

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.
 
J

Joshua Flanagan

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
 
M

mablejune

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;
 
J

Joshua Flanagan

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.
 
M

mablejune

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.
 
Joined
Jun 8, 2007
Messages
1
Reaction score
0
use server control instead of html control

After I change the html button control to server control.

All default button works.

:razz:
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top