Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8343613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:07:14+00:00 2026-06-09T06:07:14+00:00

ASP.NET Default button and default focus is not working. My application is hosted on

  • 0

ASP.NET Default button and default focus is not working. My application is hosted on IIS in my server manchine. (Servername say Server1). If i am accessing the application URL outside of machine focus and default button click is working fine (http://Server1/VPath/Login.aspx) . If i am accessing the application URL using localhost in the server it is working fine (http://localhost/VPath/Login.aspx) but focus and default button click (on Enter) is not working when i am accessing the URL using server name in the server. (http://server1/VPath/Login.aspx). What could be the issue?

Note: IE version is same in all the above cases.

Here are my code files.

Login.aspx

<asp:Panel ID="LoginWrapper" runat="server" CssClass="loginWrapper" >
    <asp:Login ID="LoginControl" runat="server" meta:resourcekey="LoginResource1" 
        DisplayRememberMe="false" OnAuthenticate="authenticate">
        <LayoutTemplate>
            <table>
                <tr>
                    <td>
                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName" meta:resourcekey="UserNameLabelResource1"
                            Text="User Name:"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="UserName" runat="server" meta:resourcekey="UserNameResource1"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                            ErrorMessage="User Name is required." ToolTip="User Name is required."
                            meta:resourcekey="UserNameRequiredResource1" Text="*"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password" meta:resourcekey="PasswordLabelResource1"
                            Text="Password:"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="Password" runat="server" TextMode="Password" meta:resourcekey="PasswordResource1"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: center; color: red">
                        <asp:Literal ID="FailureText" runat="server" EnableViewState="False" meta:resourcekey="FailureTextResource1"></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Login"
                            meta:resourcekey="LoginButtonResource1" /></td>
                </tr>
            </table>
        </LayoutTemplate>
    </asp:Login>
</asp:Panel>

Login.aspx.cs

 protected void Page_Init(object sender, EventArgs e)
    {
        Response.RedirectLocation = Request.Url.ToString();
        // bug#19156 Enter key should Login
        LoginControl.Focus();
        Page.Form.DefaultButton = ((Button)LoginControl.FindControl("LoginButton")).UniqueID;
    }

protected void Page_Load(object sender, EventArgs e)
    {
        log.Debug("Loading login Page");
        try
        {
            if (Request.QueryString["activity"] != null)
            {
                string activity = Request.QueryString["activity"].ToString();
                switch (activity)
                {
                    case "login":
                        if (Request.QueryString["Username"] != null)
                            un = Request.QueryString["Username"].ToString();
                        if (Request.QueryString["Password"] != null)
                            pw = Request.QueryString["Password"].ToString();
                        authenticate(null, null);
                        break;
                }
            }
        }
        catch (ExecutionEngineException ex)
        {
        }
        if (Request.IsAuthenticated && !IsPostBack)
        {
            Response.Redirect("~/VPath/NotAuthorized.aspx");
        }
        else if (!IsPostBack)
        {
           HideTopMenu();
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:07:15+00:00Added an answer on June 9, 2026 at 6:07 am

    I do not know why your code is not working when accessed from outside but i think the problem
    is with page_init event .

    so better i would suggest to override it and this is safe too:-

    protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Response.RedirectLocation = Request.Url.ToString();
            // bug#19156 Enter key should Login
            LoginControl.Focus();
            Page.Form.DefaultButton = ((Button)LoginControl.FindControl("LoginButton")).UniqueID;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an ASP.NET application which has the following Back button on
I just want to see error insteas of asp.net showing me default error Server
I presume only the Button server control in ASP.NET has AUTO POST BACK set
I am using one link button in an asp.net application for delete purpose. For
Background I have an ASP.NET site, hosted internally on our company's intranet server. The
I am using ASP.NET Panel to set Default Button for some Controls like TextBox
I have an application in Asp.Net and at a click of a button it
i am very new to asp.net. when someone presses a button on default.aspx, this
I create an asp.net page e.g. default.aspx. I then define a button... <asp:Button ID=btnNew
Working with asp.net, and I am trying to find a way to change default

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.