473,395 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Master Page DefaultButton/DefaultFocus

We can set the default button and focus field in ASP.Net 2.0 on the Form tag.
My form tag is in the Master page, but the controls are in containers.

I read through a few articles which did not work.

I added a "runat=server" to make the values visible to the devel. env.

I added properties to the masters codebehind:

Private strDefaultFocus As String
Private strDefaultButton As String

Public WriteOnly Property FormFocusControl() As String
Set(ByVal value As String)
strDefaultFocus = value
End Set
End Property

Public WriteOnly Property FormButtonControl() As String
Set(ByVal value As String)
strDefaultButton = value
End Set
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.frmMaster.DefaultButton = strDefaultButton
Me.frmMaster.DefaultFocus = strDefaultFocus
End Sub
In the Container, I set the default to a container control name:

CType(Master, Generic).FormButtonControl = "ibtnNext"

The button is of type asp:ImageButton.

When I run the page, I get "The DefaultButton of 'frmMaster' must be the ID
of a control of type IButtonControl."

I hope the resolution is as easy as placing the Generic assignment to a
different area. I have watched the Generic.Page_Load execute AFTER the
Container.Page_Load, so I assumed the controls were available.

Thank you
Feb 16 '07 #1
2 12979
DefaultButton and DefaultFocus works in any Panel as well...

<asp:panel id="p" runat="server" defaultbutton="btnSave">
<asp:button id="btnSave" runat="server" text="Save" />
</asp:panel>

"BigJohn" <bi*****@newsgroup.nospamwrote in message
news:25**********************************@microsof t.com...
We can set the default button and focus field in ASP.Net 2.0 on the Form
tag.
My form tag is in the Master page, but the controls are in containers.

I read through a few articles which did not work.

I added a "runat=server" to make the values visible to the devel. env.

I added properties to the masters codebehind:

Private strDefaultFocus As String
Private strDefaultButton As String

Public WriteOnly Property FormFocusControl() As String
Set(ByVal value As String)
strDefaultFocus = value
End Set
End Property

Public WriteOnly Property FormButtonControl() As String
Set(ByVal value As String)
strDefaultButton = value
End Set
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.frmMaster.DefaultButton = strDefaultButton
Me.frmMaster.DefaultFocus = strDefaultFocus
End Sub
In the Container, I set the default to a container control name:

CType(Master, Generic).FormButtonControl = "ibtnNext"

The button is of type asp:ImageButton.

When I run the page, I get "The DefaultButton of 'frmMaster' must be the
ID
of a control of type IButtonControl."

I hope the resolution is as easy as placing the Generic assignment to a
different area. I have watched the Generic.Page_Load execute AFTER the
Container.Page_Load, so I assumed the controls were available.

Thank you
Feb 17 '07 #2
Hello John,

From your description, you have some TextBox and Button controls in a
concrete page(apply a certain master page) and you're wondering how to set
the entire page form's "DefaultFocus" and "DefaultButton" as the certain
Textbox and Button in content page, correct?

Based on my research, if you want to set "DefaultButton" and "DefaultFocus"
of Htmlform in master page case, you need to use code to do it
programmatically. Also, the value you specified for the
HtmlForm.DefaultButton and HtmlForm.DefaultFocus are also different from
normal scenario. here is a blog article mentioned this(in the comments)

#Default Focus, Buttons and Validation Errors with ASP.NET 2.0
http://weblogs.asp.net/scottgu/archi...04/421647.aspx

I have tested on my local environment, and here is what you need to do in
content page:

** use control.UniqueID for HtmlForm.DefaultButton
** use control.ClientID for HtmlForm.DefaultFocus

here is the complete code of the test content page:

========content aspx==========
<%@ Page Language="C#" MasterPageFile="~/masters/site.master"
AutoEventWireup="true" CodeFile="concretepage1.aspx.cs"
Inherits="concrete_concretepage1" "%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" /><br />
<hr />
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px"
BorderStyle="solid" BorderColor="black">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Text="Button" />
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="http://static.asp.net/asp.net/images/MicrosoftASPNET.gif"
OnClick="ImageButton1_Click" /></asp:Panel>
</asp:Content>

=========content codebehind========
public partial class concrete_concretepage1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

Page.Form.DefaultButton = ImageButton1.UniqueID;
Page.Form.DefaultFocus = TextBox2.ClientID;

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Button1_Click..........");
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Write("Button2_Click..........");
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.Write("ImageButton1_Click..........");
}
}
===========================================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chriis | last post by:
How do you define the defaultbutton for a web page that has a master page since the content page has no form tags to define the defaultbutton attribute? Nothing I try seems to work. Thanks for...
3
by: dpomt | last post by:
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...
5
by: Tyler Carver | last post by:
I have found a situation where the DefaultButton and DefaultFocus stop working under FireFox. I'm looking for any kind of fix or work around. The problem seems to happen when setting a control...
12
by: David Thielen | last post by:
Hi; I have my <form> in the master page because the master page includes the menu for all pages. But I would like to set the default button and control to place the caret in for each page. Is...
2
by: dotnetjose | last post by:
Hi Folks, My subject message pretty musch explains it. By Default the Form definition sits at the Master Page file. Is there a way I can access the setting from my Content Page that uses a...
1
by: Dev | last post by:
hi i have master page in which i have form and now in content page i need to set the defaultbutton. now i have one solution for that in content page "HtmlForm mainform =...
3
by: lanem | last post by:
Do you put your form on the master page or in each individual page? I use a master page for most of my site. Should the form tag be in the master page? Thanks.
7
by: Tim_Mac | last post by:
this is a re-post of an earlier message. i'm posting it under my MSDN alias for a better chance of reply :) when you press return in a multiline textbox, you expect to insert a newline. ...
6
by: jelle.huygen | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.