Default button of a page

J

jelle.huygen

Hello,

I've worked on a website in ASP.NET 2.0 where, on every page, login-
button of a login control is set as the default button. The login-
control is on the masterpage of the website. In the prerender-method
of the masterpage, I have placed the following code:

Login lg = (Login)lgView.FindControl("lgLogin");
if (lg != null)
{
Button btn = (Button)lg.FindControl("LoginButton");
if (btn != null)
Page.Form.DefaultButton = btn.UniqueID;
}

The website is running in a production environment and a couple of
times a day we get the following exception:

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

I can't reproduce the exception; it appearce to occure randomly.

Does anyone experienced the same problem or does anyone have a
solution?

Kind regards,
Jelle
 
C

Cowboy \(Gregory A. Beamer\)

You may have to wrap the point where the code is causing an exception and
find a) the page it is happening on and b) the control it thinks it is
setting as default. The answer to those two questions will help you
determine why it is happening.
 
B

bruce barker

some form has a lgButton thats not a really a Login causing the cast to
blow. change your code to:

Login lg = lgView.FindControl("lgLogin") as Login;
if (lg != null)


-- bruce (sqlwork.com)
 
G

Guest

Hello,

I've worked on a website in ASP.NET 2.0 where, on every page, login-
button of a login control is set as the default button. The login-
control is on the masterpage of the website. In the prerender-method
of the masterpage, I have placed the following code:

Login lg = (Login)lgView.FindControl("lgLogin");
if (lg != null)
{
Button btn = (Button)lg.FindControl("LoginButton");
if (btn != null)
Page.Form.DefaultButton = btn.UniqueID;
}

The website is running in a production environment and a couple of
times a day we get the following exception:

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

I can't reproduce the exception; it appearce to occure randomly.

Does anyone experienced the same problem or does anyone have a
solution?

Kind regards,
Jelle

It looks like it is an issue with MasterPage

Please check this
http://www.spaanjaars.com/QuickDocId.aspx?QUICKDOC=374
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top