English 中文(简体)
如何把重点放在违约控制上?
原标题:how to set the focus to a control by default?
  • 时间:2011-04-29 12:43:28
  •  标签:
  • asp.net

i 是否有标识控制和建立用户控制,即我的网页......如果页数......怎么能做到,那么 cur子就应当放在标识控制的用户名框上?

<asp:LoginView ID="LoginView1" runat="server">
              <LoggedInTemplate>
                  Bingo..!!! Youuuuu did it...<asp:LoginName ID="LoginName1" runat="server" />.



              </LoggedInTemplate>
              <AnonymousTemplate>

                  <asp:DropShadowExtender ID="DropShadowExtender1" runat="server" 
                                            TargetControlID="Panel1" 
                                            Rounded="true" 
                                            Opacity=".38">
                  </asp:DropShadowExtender>
                  <asp:Panel ID="Panel1" runat="server" 
                                         BackColor="Silver">
                  <asp:Login ID="Login1" runat="server" 
                                         DestinationPageUrl="~/ViewCart_aspx/ViewCart.aspx" 
                                         Height="152px" 
                                         Width="396px" 
                                         RememberMeSet="True" 
                                         OnLoggedIn="ContinueButton_Click" >
                      <LayoutTemplate>
                          <fieldset>
                          <table border="0" 
                                 cellpadding="1" 
                                 cellspacing="0" 
                                 style="border-collapse:collapse;">
                              <tr>
                                  <td>
                                      <table border="0" cellpadding="0" style="height:152px;width:396px;">
                                          <tr>
                                              <td align="center" colspan="2">
                                                 <h3>Log In</h3> </td>
                                          </tr>
                                          <tr>
                                              <td align="right">
                                                  <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                                              </td>
                                              <td>&nbsp;
                                                  <asp:TextBox ID="UserName" runat="server" Width="150px" TabIndex="0"></asp:TextBox>
                                                  <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                                      ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                                      ToolTip="User Name is required." ValidationGroup="ctl01$Login1">*</asp:RequiredFieldValidator>
                                              </td>
                                          </tr>

页: 1 用户Name 文本箱处于标识控制之内,因此无法获取其财产,我如何找到控制权?

最佳回答

EDIT: as you mentioned in comments, you want to set your login button to be clicked as a default button. For this you need to set this button as a default button.

令人不舒服的是,正如我在对你的提问发表评论时所问的那样,你采取了适当的形式。 因此,我假定 log子位于与用户名箱相同的名称集装箱内,其名称为<代码>btn Carloin,你可将这一控制规定为默认控制。 HtmlForm.DefaultButton property, so:

您可使用Page.SetFocus。 它把浏览器的重点放在特定的控制上:

Page.SetFocus(txtName);

如果你想要达到文本箱,你可以仅使用:

var login1 = LoginView1.FindControl("Login1") as Login;
if (login1 != null)
{
    var txtUserName = login1.FindControl("UserName");
    if (txtUserName != null)
    {
        Page.SetFocus(txtUserName);
    }

    var btnLogin = login1.FindControl("btnLogin");
    if (btnLogin != null) 
    {
         Page.Form.DefaultButton = btnLogin.UniqueID;
    }
}

但指出:

For the LoginView control, when being added onto a page, at a certain time, only one Template (anonymous or loggedIn ) is applied on the Control instance, so at that time, we can only retrieve the reference of those controls in the active template( can t access those in the non-active template).

问题回答

英文版

textbox1.focus();

如果可能的话,则通过使用你必须掌握的身份证,才能在守则中控制。

The Default Focus property consider in this case:

// inside page_load, LoginUser is the Login control
Page.Form.DefaultFocus = LoginUser.FindControl("Username").ClientID;

Related question: Set focus to textbox in ASP.NET Login control on page load





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签