Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

works on localhost but not on webserver

I am trying to make the Enter key work during login for my app at www.lucidequipment.com by setting up a default button in a panel.  The code works in localhost mode, but on the web server gives the often seen error about needing the default button to be of type IButtonControl. What am I doing wrong?

My best guess is that the button is not properly identified in the code behind.

Protected Sub Login1_PreRender(sender As Object, e As EventArgs)
        Dim btnLoginDefault As Button = TryCast(Login1.FindControl("LoginButton"), Button)
        pnlLogin.DefaultButton = btnLoginDefault.UniqueID
    End Sub

Open in new window

0
Mark Klein
Asked:
Mark Klein
  • 5
  • 2
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
This is what I get from your web server:

Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

Are those the same as you have on your computer at 'localhost'?
0
 
Mark KleinAuthor Commented:
that's the AspNet version. My default browser in Chrome, not MS.  Where do I find the IIS version?
0
 
Dave BaldwinFixer of ProblemsCommented:
Browser doesn't matter because ASP.NET is run on the server.  IIS versions are tied to the Operating System.  See here: http://support.microsoft.com/kb/224609
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
Mark KleinAuthor Commented:
I eventually realized that. I'm using Win7 in a dual boot setup on a Mac with Parallels, so IIS at 7.5 is probably OK.

Been doing this for a while w/o this problem.  I'm a relative newbie, a geezer back to programming after (literally) 50 years, so there is a lot I don't know. I built the app you see for my son, now doing defensive programming trying to handle users who press Enter instead of the button they should.

I suspect the problem is related to the button identifier, which changes during compilation. I am trying to make the button on the screen the defaultbutton in a panel.  I've seen several posts about this situation being "squirrely" in VWD, and some need to modify the UniqueID that I append to the the button ID.
0
 
Mark KleinAuthor Commented:
My code, shown below, is unable to find the button that I want assigned as the defaultbutton. Hence the Enter key is directed elsewhere, which is probably while it's failing.  From reading around the net, it seems that because this login page is coupled to a master page, that master page is causing the problem.

Protected Sub Login1_Load(sender As Object, e As System.EventArgs) Handles Login1.Load
        MyBase.LogActivity("Visiting the Login page.")
        Dim btnLoginDefault As Button = TryCast(FindControl("Login1$LoginButton"), Button)
        pnlLogin.DefaultButton = btnLoginDefault.UniqueID
    End Sub

Open in new window


I've set a breakpoint on the Dim line, and the breakpoint is reached. The code goes through here and fails here
0
 
Mark KleinAuthor Commented:
I "solved" the problem by not using the panel defaultbutton.  Inside the Load event for the page I put

  Dim FirstTextBox As TextBox = TryCast(Login1.FindControl("username"), TextBox)
        Page.Form.DefaultFocus = FirstTextBox.ClientID
        Dim btnLoginDefault As Button = TryCast(Login1.FindControl("LoginButton"), Button)
        Page.Form.DefaultButton = btnLoginDefault.UniqueID

Open in new window

I was led to this approach by

http://imar.spaanjaars.com/374/how-do-i-set-the-defaultfocus-or-defaultbutton-in-a-page-based-on-a-master-page-in-aspnet-20

Why the code based on the panel default button doesn't work, or why visual web developer led me astray by having my code work in localhost but not on web server, I still don't know
0
 
Mark KleinAuthor Commented:
Had to solve this myself.  Still don't know why my original code only worked in localhost.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now