473,788 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=serv er" to make the values visible to the devel. env.

I added properties to the masters codebehind:

Private strDefaultFocus As String
Private strDefaultButto n As String

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

Public WriteOnly Property FormButtonContr ol() As String
Set(ByVal value As String)
strDefaultButto n = value
End Set
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Me.frmMaster.De faultButton = strDefaultButto n
Me.frmMaster.De faultFocus = strDefaultFocus
End Sub
In the Container, I set the default to a container control name:

CType(Master, Generic).FormBu ttonControl = "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_Lo ad execute AFTER the
Container.Page_ Load, so I assumed the controls were available.

Thank you
Feb 16 '07 #1
2 12994
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*****@newsgr oup.nospamwrote in message
news:25******** *************** ***********@mic rosoft.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=serv er" to make the values visible to the devel. env.

I added properties to the masters codebehind:

Private strDefaultFocus As String
Private strDefaultButto n As String

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

Public WriteOnly Property FormButtonContr ol() As String
Set(ByVal value As String)
strDefaultButto n = value
End Set
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Me.frmMaster.De faultButton = strDefaultButto n
Me.frmMaster.De faultFocus = strDefaultFocus
End Sub
In the Container, I set the default to a container control name:

CType(Master, Generic).FormBu ttonControl = "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_Lo ad 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 "DefaultFoc us" and "DefaultBut ton" as the certain
Textbox and Button in content page, correct?

Based on my research, if you want to set "DefaultBut ton" and "DefaultFoc us"
of Htmlform in master page case, you need to use code to do it
programmaticall y. Also, the value you specified for the
HtmlForm.Defaul tButton and HtmlForm.Defaul tFocus 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.UniqueI D for HtmlForm.Defaul tButton
** use control.ClientI D for HtmlForm.Defaul tFocus

here is the complete code of the test content page:

========content aspx==========
<%@ Page Language="C#" MasterPageFile= "~/masters/site.master"
AutoEventWireup ="true" CodeFile="concr etepage1.aspx.c s"
Inherits="concr ete_concretepag e1" "%>
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
Runat="Server">
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
Text="Button" /><br />
<hr />
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px"
BorderStyle="so lid" BorderColor="bl ack">
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<asp:Button ID="Button2" runat="server" OnClick="Button 2_Click"
Text="Button" />
<asp:ImageButto n ID="ImageButton 1" runat="server"
ImageUrl="http://static.asp.net/asp.net/images/MicrosoftASPNET .gif"
OnClick="ImageB utton1_Click" /></asp:Panel>
</asp:Content>

=========conten t codebehind===== ===
public partial class concrete_concre tepage1 : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{

Page.Form.Defau ltButton = ImageButton1.Un iqueID;
Page.Form.Defau ltFocus = TextBox2.Client ID;

}
protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Write( "Button1_Click. .........");
}
protected void Button2_Click(o bject sender, EventArgs e)
{
Response.Write( "Button2_Click. .........");
}
protected void ImageButton1_Cl ick(object sender, ImageClickEvent Args e)
{
Response.Write( "ImageButton1_C lick.........." );
}
}
=============== =============== =============

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
1068
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 your help, Chris
3
4915
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 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;
5
1831
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 that is part of another control, like a templated control. The docs say to use the UniqueID in this case. In the example below I am trying to set controls in the Login control's LayoutTemplate. protected void Page_Load(object sender, EventArgs...
12
4578
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 there a way to do this? (My understanding is this has to be done in the form tag.) -- thanks - dave david_at_windward_dot_net
2
3727
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 Master Page? Thanks in advance.
1
1478
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 = (HtmlForm)Master.FindControl("frmMain"); mainform.DefaultButton = btnSave.UniqueID;" i have use this code that solve my problem but now main problem is that i have around 500 page in which i have to
3
2020
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
2813
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. However, if you set the Form.DefaultButton property, whatever javascript code is employed by Asp.Net to handle this functionality intercepts the key press and submits the form, when using Firefox. This is a potentially serious problem and certainly a...
6
5641
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 the prerender-method of the masterpage, I have placed the following code: Login lg = (Login)lgView.FindControl("lgLogin"); if (lg != null) {
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10173
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.